+ 1

Can I use a class as a member of an other class? Does it make sense?

In C, when I had a " struct point{ int x; int y; }; " structure, it was a good practice when I made a triangle using the 'point': struct triangle{ struct point A; struct point B; struct point C; }; But in C++ classes may contain functions, unlike struct. So, does it make sense if I do the same with classes, or should I use struct? What if 'class Point' has a member function? Which is the preferred way? Do I have to inherit a class instead of nesting into another class?

18th Nov 2016, 3:06 PM
Marcell Juhasz
1 Odpowiedź
+ 2
Yes we can do that. For more info go to http://stackoverflow.com/questions/10576334/a-class-as-data-member-of-another-class this will help someway :)
18th Nov 2016, 7:36 PM
Deepak Kumar
Deepak Kumar - avatar