C++ structures

Started by
3 comments, last by Fruny 18 years, 8 months ago
This is a follow up from an earlier post...didn't want to hijack it so started another. In that post it was said that structs (C++) are the same as classes except that all members (methods and variables) are public. Does this mean that structs support instansiation/constructors/destructors/inhertience/polymorphism etc as classes do?
Gary.Goodbye, and thanks for all the fish.
Advertisement
Yes. Also, they support private and protected access levels, but the default is public (unlike C++ classes, whose default access level is private).
Yes, I believe so. The ONLY difference is that classes default to private, and structs default to public.
my siteGenius is 1% inspiration and 99% perspiration
Interesting...thanks guys (and gals).
Gary.Goodbye, and thanks for all the fish.
The public/private defaults also apply to base classes:

struct Foo {};struct Bar {};struct Quux1 :        Foo, private Bar {};  // Quux1 and Quux2class  Quux2 : public Foo,         Bar {};  // are identical.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement