Problem accessing private member of base class in friend class through derived object.
Radhika Ganganna
Radhika.Ganganna@Oracle.com
Fri Dec 30 05:02:00 GMT 2005
Hi,
I have a program that has a template base class with a private data member
in it. It has a derived class. And both the base and derived class have a
common friend class. All these classes are part of a namespace. When I try
to access private data member of base class, through the derived class in
friend class, I get the following compilation error:
Linux:/user/rgangann >gcc rad.cpp
rad.cpp: In member function `void radhika::friendclass::disp()':
rad.cpp:4: error: `char**radhika::Base<char*>::num1' is private
rad.cpp:17: error: within this context
The code is as below:
namespace radhika {
template<class T> class Base { friend class friendclass;
private: T* num1; };
class Derived : protected Base <char * > {
friend class friendclass;
char ** num2;
};
class friendclass
{
void disp(void)
{
Derived d;
char** a;
a = d.num1;
}
} ;
}; // End namespace radhika
int main()
{
return 0;
}
Im using gcc3.4.3. Let me know if this is an existing problem and how to
solve this problem. Also I find that when I do not have the classes in
namespace, the program works fine.
Regards,
Radhika
More information about the Gcc-help
mailing list