This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problem accessing private member of base class in friend class through derived object.
- From: Purnendu <purnendu at gmail dot com>
- To: Radhika Ganganna <Radhika dot Ganganna at oracle dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 30 Dec 2005 12:14:19 +0530
- Subject: Re: Problem accessing private member of base class in friend class through derived object.
- References: <005201c60cfe$ab5a82e0$5492b00a@INHEXBLR.COM>
Hi,
U missed the forward declaration for "friendclass".
I was using gcc 3.4.0 on a SUN box.
But i could not figure out why it was working without the namespace.
Any pointers?
On 12/30/05, Radhika Ganganna <Radhika.Ganganna@oracle.com> wrote:
> 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
>
>
>
>
--
Purnendu Ghosh
FLEXTRONICS SOFTWARE SYSTEMS
#18/1,Outer Ring Road,
Panathur Post,
Bangalore 560 087,INDIA
+91-080-5106 7837 Phone
+91-080-5126 6501 Fax
+91-9886892863 Mobile
---------------------------------------------------
If you can DREAM it you can DO it
---------------------------------------------------