// { dg-do assemble }
|
// { dg-do assemble }
|
// GROUPS passed visibility
|
// GROUPS passed visibility
|
// visibility file
|
// visibility file
|
// From: Gordon Joly
|
// From: Gordon Joly
|
// Date: Wed, 21 Apr 93 09:42:07 +0100
|
// Date: Wed, 21 Apr 93 09:42:07 +0100
|
// Subject: /*** BUG REPORT : THE MYTH OF PRIVATE INHERITANCE ***/
|
// Subject: /*** BUG REPORT : THE MYTH OF PRIVATE INHERITANCE ***/
|
// Message-ID: <9304210842.AA01815@life.ai.mit.edu>
|
// Message-ID: <9304210842.AA01815@life.ai.mit.edu>
|
#include
|
#include
|
|
|
class A {
|
class A {
|
private:
|
private:
|
int number;
|
int number;
|
public:
|
public:
|
A(int i) : number(i)
|
A(int i) : number(i)
|
{}
|
{}
|
virtual ~A()
|
virtual ~A()
|
{}
|
{}
|
virtual void Number(int c) // { dg-error "inaccessible" }
|
virtual void Number(int c) // { dg-error "inaccessible" }
|
{ number = c; }
|
{ number = c; }
|
virtual int Number() // { dg-error "inaccessible" }
|
virtual int Number() // { dg-error "inaccessible" }
|
{ return number; }
|
{ return number; }
|
};
|
};
|
|
|
class B : private A {
|
class B : private A {
|
private:
|
private:
|
int second_number;
|
int second_number;
|
public:
|
public:
|
B(int c, int i) : second_number(c), A(i)
|
B(int c, int i) : second_number(c), A(i)
|
{}
|
{}
|
virtual ~B()
|
virtual ~B()
|
{}
|
{}
|
|
|
virtual void firstNumber(int b) // renames member function Number(int) of class A
|
virtual void firstNumber(int b) // renames member function Number(int) of class A
|
{ A::Number(b); }
|
{ A::Number(b); }
|
virtual int firstNumber() // renames member function Number() of class A
|
virtual int firstNumber() // renames member function Number() of class A
|
{ return A::Number(); }
|
{ return A::Number(); }
|
};
|
};
|
|
|
|
|
|
|
|
|
class C {
|
class C {
|
private:
|
private:
|
B* bobject;
|
B* bobject;
|
public:
|
public:
|
C(B* bp) : bobject(bp)
|
C(B* bp) : bobject(bp)
|
{}
|
{}
|
virtual ~C()
|
virtual ~C()
|
{}
|
{}
|
//
|
//
|
// the following two functions access
|
// the following two functions access
|
// private member functions of class B
|
// private member functions of class B
|
// and they should not be able to do so
|
// and they should not be able to do so
|
//
|
//
|
virtual void setBValue(int i)
|
virtual void setBValue(int i)
|
{ if (bobject) bobject->Number(i); } // { dg-error "this context|accessible base" }
|
{ if (bobject) bobject->Number(i); } // { dg-error "this context|accessible base" }
|
virtual int getBValue()
|
virtual int getBValue()
|
{ if (bobject) { return bobject->Number(); } return 0; } // { dg-error "this context|accessible base" }
|
{ if (bobject) { return bobject->Number(); } return 0; } // { dg-error "this context|accessible base" }
|
};
|
};
|
|
|
|
|
int main()
|
int main()
|
{
|
{
|
B* bobject = new B(2, 1);
|
B* bobject = new B(2, 1);
|
C* cobject = new C(bobject);
|
C* cobject = new C(bobject);
|
cobject->setBValue(8);
|
cobject->setBValue(8);
|
std::cout << cobject->getBValue() << std::endl;
|
std::cout << cobject->getBValue() << std::endl;
|
delete bobject;
|
delete bobject;
|
delete cobject;
|
delete cobject;
|
}
|
}
|
|
|
|
|
|
|
|
|