

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The concept of constructors in c++, their special characteristics, and the three types: default, parametrized, and copy constructors. It also introduces destructors.
What you will learn
Typology: Schemes and Mind Maps
1 / 2
This page cannot be seen from the preview
Don't miss anything!
Constructor in C++ A class constructor is a special member function of a class that is executed whenever we create new objects of that class. A constructor will have an exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values for certain member variables.
// set line length line.setLength(6.0); cout << "Length of line : " << line.getLength() <<endl; return 0; } class A { int x; pub lic: A(); //Constructor }; Constructors are special class functions which perform initialization of every object. The Compiler calls the Constructor whenever an object is created. Constructors initialize values to object members after storage is allocated to the object.
Constructors are of three types:
The destructor is a special class function which destroys the object as soon as the scope of an object ends. The destructor is called automatically by the compiler when the object goes out of scope. The syntax for destructor is same as that for the constructor, the class name is used for the name of the destructor, with a tilde ~ sign as a prefix to it. class A { public: ~A(); }; Destructors will never have any arguments.