c++ structs

Started by
2 comments, last by amish1234 20 years, 1 month ago
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)
___________________________________________________________Where to find the intensity (Updated Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)
Advertisement
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:
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  {  }; 

--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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 Dec 28, 2004)Member of UBAAG (Unban aftermath Association of Gamedev)

This topic is closed to new replies.

Advertisement