🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Naoki Saito (GEO-002) Ext. 5471 Thu, 30 Nov 1989 22:14
protected member access
#648
Author: Naoki Saito (GEO-002) Ext. 5471
Date: Thu, 30 Nov 1989 22:14
46 lines
1390 bytes
	The function void f(Base& b) in the following program caused an error
if I used the Sun C++ 2.0 translator as follows:

""prot.cc", line 18: error:  Derived::f() cannot access Base::a: protected
member 

Howerver, g++-1.34.2 on the Sun3 OS 4.0.1 did not produce any error.  Which
behavior is correct? (I think this is a 1.34.2 bug...)  This g++ behavior is
different from the g++-1.36.x?

Thanks in advance,

Naoki Saito (saito@sdr.slb.com)
Schlumberger-Doll Research

========================prot.cc================================================
#include <stream.h>

class Base
{
protected:
  int a;
public:
  Base() { a = 100; }
  ~Base() {};
  int get_a() { return a; }
};

class Derived : public Base
{
public:
  Derived() : () { a = 10; }
  ~Derived() {};
  void f(Base& b) { cout << a + b.a << "\n"; }
  void g(Base& b) { cout << a + b.get_a() << "\n"; }
};

main()
{
  Base x;
  Derived y;

  y.f(x);
  y.g(x);
}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads