Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structs versus Classes

Similar presentations


Presentation on theme: "Structs versus Classes"— Presentation transcript:

1 Structs versus Classes

2 Similarities Both can have public and private sections

3 Similarities Both can have public and private sections
Both can hold member variables

4 Similarities Both can have public and private sections
Both can hold member variables Both can hold member functions

5 Differences Struct members default to public

6 Differences Struct members default to public
Class members default to private

7 Equivalent Examples struct boot { float m_size; float m_heelheight; };
public: float m_size; float m_heelheight; }; class boot { public: float m_size; float m_heelheight; };

8 Equivalent Examples class table { private: int m_numLegs;
float m_topArea; public: void fold(); }; class table { int m_numLegs; float m_topArea; public: void fold(); }; struct table { void fold(); private: int m_numLegs; float m_topArea; };

9 Traditionally Classes are used when you need an object that has functionality Structs are used when you need an object that is composed entirely of public variables This is a hold-over from the C programming language when there were no classes and structs could not provide functionality

10 End of Session


Download ppt "Structs versus Classes"

Similar presentations


Ads by Google