c++ structs
I always thought that structs were like a class that had no methods and couldn''t be inherited. I believe this is true in C.
However, C++, having classes, seems to have made structs much more similar to a class. Right now I''m looking at code that has structs with methods and constructors/destructors and struct inheritance.
So what''s the difference between structs and classes in C++?
___________________________________________________________
Where to find the intensity (Updated Mar 20, 2004)
structs'' members are public by default, whereas classes'' are private by default. both can be overridden by using the "private:" or "public:" tags.
structs default to public inheritance, classes default to private inheritance.
the following are exactly the same:
structs default to public inheritance, classes default to private inheritance.
the following are exactly the same:
struct Base { int publicVar; private: int privateVar; };struct Derived1 : Base { };struct Derived2 : private Base { };
class Base { int privateVar; public: int publicVar; };class Derived1 : public Base { };class Derived2 : Base { };
Did you even consider searching the forums before you asked this? Not only that, you''ve actually participated in these struct vs. class threads before; like here. What''s even worse is that in *that* thread you remembered that structs could have constructors.
Well, when I wrote that reply, I''d seen structs with constructors before, but not other methods, and I hadn''t seen inheritance with structs.
___________________________________________________________
Where to find the intensity (Updated Mar 20, 2004)
___________________________________________________________
Where to find the intensity (Updated Mar 20, 2004)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement