Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

including class as member in struct

Tags:

c++

c

oop

I have to add a class object as member within a c struct.

Is there any prohibition doing this.

Regards, iSight

like image 565
boom Avatar asked Feb 09 '11 12:02

boom


1 Answers

I'll assume you're talking about C++, since there is no concept of a "class" in C - although you certainly can have a struct as a member of another struct.

Apart from one unimportant detail, class and struct are identical, and both are often referred to as "class types". Anything you can do with a class (such as having a member of class type), you can also do with a struct.

If you're interested, the only difference is the default accessibility of members and base classes; public for struct, and private for class.

like image 141
Mike Seymour Avatar answered Oct 14 '22 16:10

Mike Seymour