Содержание
- 2. OUTLINE… PREPROCESSOR WRAPPERS CONSTRUCTORS AND DESTRUCTORS IN C++ TYPES OF CONSTRUCTORS IN C++ Default Constructor Parameterized
- 3. PREPROCESSOR WRAPPERS Prevents code from being included more than once #ifndef – “if not defined” Skip
- 4. Dr.S.Manimurugan
- 5. Dr.S.Manimurugan
- 6. Simple Class and objects Dr.S.Manimurugan
- 7. Dr.S.Manimurugan
- 8. Constructors and Destructors in C++ Constructors are special class functions which performs initialization of every object.
- 9. While defining a constructor you must remember that the name of constructor will be same as
- 10. Types of Constructors in C++ Constructors are of three types: Default Constructor Parameterized Constructor Copy Constructor
- 11. Default Constructors Default constructor is the constructor which doesn't take any argument. It has no parameter.
- 12. Parameterized Constructors These are the constructors with parameter. Using this Constructor you can provide different values
- 13. COPY CONSTRUCTOR A copy constructor is a member function which initializes an object using another object
- 14. #include using namespace std; class SC { private: int x, y; //data members public: SC(int x1,
- 15. DESTRUCTORS IN C++ Destructor is a special member function that is executed automatically when an object
- 16. CONSTRUCTORS AND DESTRUCTORS IN C++ Constructors are special class functions which performs initialization of every object.
- 17. STRUCTURE OF C++ DESTRUCTORS /*...syntax of destructor....*/ class class_name { public: class_name(); //constructor. ~class_name(); //destructor. }
- 18. #include using namespace std; class ABC { public: ABC () //constructor defined { cout } ~ABC()
- 19. C++ CONSTRUCTORS OVERLOADING Every constructor has same name as class name but they differ in terms
- 20. /*.....A program to highlight the concept of constructor overloading.......... */ #include using namespace std; class ABC
- 21. ABC(int a,int b) //constructor 3 with two argument { x = a; y = b; }
- 22. Dr.S.Manimurugan 1. What is called a class constructor? What is the purpose of class constructor? A
- 23. Dr.S.Manimurugan 3. Can the constructor have parameters? Examples of constructors with different number of parameters The
- 24. Dr.S.Manimurugan // class methods void SetDate(int d, int m, int y); // set a new date
- 25. Dr.S.Manimurugan // set a new date void CMyDate::SetDate(int d, int m, int y) { day =
- 26. Dr.S.Manimurugan // retutn year int CMyDate::GetYear(void) { return year; } int main() { CMyDate obj; CMyDate
- 27. Dr.S.Manimurugan 4. Is it necessary to declare a constructor in a class? Not. When you create
- 28. Dr.S.Manimurugan // A class that defines a point on the coordinate plane class CMyPoint { int
- 30. Скачать презентацию