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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> 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
---------------------------------------------------


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux