topimaurola wrote: > Hi, > > the following code doesn't compile on Gnu g++ (4.2.4) > > Any ideas why? > > the marked "POINT 1" below, is member function of derived > class. It should have access right to c0. > > Topi > > ******* > > > class c1a; > class c1b; > > class c0 > { > friend class c1a; > protected: > int prot; > private: > int priv; > public: > int pub; > void mf0() > { > c0 *k=this; > k->pub; > k->prot; > k->priv; > } > }; > > class c1b:public c0 > { > public: > void mf1(void) > { > c0 *k=this; > k->pub; > k->prot; // POINT 1. this point doesn't compile. > k->priv; // POINT 2. this is ok not to compile, no friend. > } > };
Of course that won't work. You can only modify protected members of the derived class. Compilers aren't smart enough to track across pointer assignments. Maybe you meant this instead: class c1b:public c0 { public: void mf1(void) { pub; prot; priv; } }; -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/