Download presentation
Presentation is loading. Please wait.
Published byEllen Russell Modified over 9 years ago
1
Class and Structure
2
2 Structure Declare using the keyword struct purpose is to group data Default visibility mode is public A struct doesn't have a constructor or destructor Cannot support overloaded operators. Cannot use C++-specific features such as inheritance and member functions. A structure couldn't be null like a class.
3
3 Class Declare using the keyword class A class should be used for grouping data and methods that operate on that data The class default access type is private Classes have a public and private members The default mode for inheritance is private. classes are used to encapsulate data and the functions Class support constructors and destructors Class support operator overloading & function Overloading Class can be declare al null
4
4 Class Vs Structure Members of a class are private by default and members of struct are public by default class Test { int x; // x is private }; void main() { Test t;// class boject t.x = 20; // compiler error // because x is private } struct Test { int x; // x is public }; void main() { Test t; t.x = 20; // works fine because x is public }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.