They both hold constructors, destructors, methods, members, privacy, protection and inheritance. The only difference is that struct's were used in C, when classes didn't exist. However, in C struct's, privacy and protection didn't exist, member methods weren't allowed, constructors and destructors didn't exist. In C++ on the other hand, struct's are just as powerful as classes; in my opinion.
Can you derive structures from other structures and have virtual functions? Polymorphic function behavior is possible only with classes. Lot of power there!
struct Foo : /* if left unspecified, public by default */ Base
{
/* If left unspecified, public by default */
int member_variable;
Foo();
virtualvoid frobnicate();
~Foo();
Foo& operator=( Foo rhs );
};
class Foo : /* if left unspecified, private by default */ Base
{
/* If left unspecified, private by default */
public: // Better make these public...
int member_variable;
Foo();
virtualvoid frobnicate();
~Foo();
Foo& operator=( Foo rhs );
};
JSmith is completely correct. fun2code is wrong wrong wrong.
Can you derive structures from other structures and have virtual functions?
Yes.
Polymorphic function behavior is possible only with classes.
That's what we in the trade call a "big fat lie", or possibly twisting of words if you end up saying that in C++ a structure is just a class by another name.
I know JSmith made it clear, but that kind of lie needs to be really, really killed.
Oops - I stand corrected corrected corrected!
I should have researched it instead of going with my ill formed impression.
http://en.wikipedia.org/wiki/C%2B%2B_structures_and_classes
It is worth saying that a LONG LONG time ago (not even in a galaxy far far away), there WAS a big difference between class and struct in C++. But those times are gone.