Download presentation
Presentation is loading. Please wait.
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
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.