This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem accessing private member of base class in friend class through derived object.


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;
}
?
?
I?m 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
??????????????????????????????????????????????????????????? 
?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]