Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - Declaring a struct pointer inside a member function.
In the following code the declaration of bar *x is fine in x() because its a member of class foo but its not OK in y() because its a friend function: class foo { public: void x() { bar *x; // This declaration is OK. } friend void y() { bar *x; // Type bar is unavailable here. } private: struct bar { int value; bar *next; }; }; I don't understand this because I thought that the declaration of a function to be a friend of the class was to allow it to have access to all the private values and types in the class. That is to say treat the function as if it was a member of the class. But this is not happening and I am getting frustrated with C++ being so fussy. It seems to me perfectly reasonable that y() should be able to declare pointers of type bar. The only I can get this to work is to take the declaration of bar outside of the declaration of foo i.e. both are first level declarations. I don't want that because bar is only supposed to be used by foo. Thanks, Edward Oct 03 2006
Hi, Edward A. Waugh wrote ...In the following code the declaration of bar *x is fine in x() because its a member of class foo but its not OK in y() because its a friend function: class foo { public: void x() { bar *x; // This declaration is OK. } friend void y() { bar *x; // Type bar is unavailable here. } private: struct bar { int value; bar *next; }; }; I don't understand this because I thought that the declaration of a function to be a friend of the class was to allow it to have access to all the private values and types in the class. That is to say treat the function as if it was a member of the class. Oct 05 2006
|