use friend functions
#include <iostream>
using namespace std;
class c2;
class c1
{
public:
friend c2;
c1() {}
private:
void SayHello() {cout << "Hello\n";}
};
class c2
{
public:
c2() { p1 = new c1;}
~c2() {delete p1;}
void Hello() {p1->SayHello();}
private:
c1* p1;
};
class c3
{
public:
c3()
{
c2 o2;
o2.Hello();
}
};
int main()
{
c3 o3;
return 0;
}
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343