Im looking for some help or a tutorial about programming
classes inside a class
Im looking for some help or a tutorial about programming
classes inside a class
What do you mean??? Like this
Code:class foo{ public: class bar{}; }; int main() { foo *a = new foo; foo::bar *b = new foo::bar; delete a; delete b; return 0; }
Give an example of your design. For example, how are the classes related?
Kuphryn
just a small add-on to fordys code.....
This is private nesting.
so as you see any classes nested in the public side of a class become part of the interface for that class. For instance, STL classes define publically nested iterator classes. Whereas for instance private nesting could be used to hide the implementation details of a node in a linked list. The node need not be part of the interface and is but an implementation detail so this should be hidden in the private side of the class.Code:class foo{ private: class bar{}; }; int main() { foo *a = new foo; // fine foo::bar *b = new foo::bar; // compiler error bar is private to foo delete a; delete b; return 0; }
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
Code:#include <iostream> using namespace std; class abc { public: class def { public: void ghi(); }; }; void abc::def::ghi() { cout << "jkl"; } void main() { }
For example how can i call ghi()? (forgive me for the code above
but im new to this forum and not quite know how things work)
[EDIT]Code tags added by Hammer. Please read this thread
I'd guess:
Code:#include <iostream> using namespace std; class abc { public: class def { public: void ghi(); }; }; void abc::def::ghi() { cout << "jkl"; } int main() { abc::def m; m.ghi(); return 0; }
Nice! it worked! thanks allot!