What is the different between the two? Just visibility issues? So you can think of a class as an advanced structure
What is the different between the two? Just visibility issues? So you can think of a class as an advanced structure
Essentially, struct and class are interchangable if we ignore visibility. Using visibility keywords allows us to "change one to the other":
is the same asCode:struct x { private: ... };
And these two are the same:Code:class x { ... };
I personally prefer to use struct to indicate that the object is "plain data" and class to indicate objects that are not "plain data". "plain data" here means that there are no (explicit) constructors and no other member functions. That is a personal/company style choice, however, and others may have other opinions/thoughts on the subject.Code:class y { public: ... }; struct y { ... };
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Also along the lines of visibility, note that classes declared with the class keyword have private base classes by default (i.e., private inheritance is the default), while those declared with the struct keyword have public base classes by default (i.e., public inheritance is the default).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
>> I personally prefer to use struct to indicate that the object is "plain data".
It's not just you, this is a common idiom.