티스토리 뷰

C++

Constructor and Destructor in C++

seoca 2018. 11. 6. 15:28



      Constructor and Destructor with simple example code


     Constructors are called as soon as an object is created


- It does not have a return type and has the same name as class name. 

In case there is no constructor or destructor, the compiler creates default constructor or destructor but if there is at least one constructor, the default constructor is not created by default.

They both have to be public.

A class allows multiple constructors but destructor must be the one. 



example code




Result





'C++' 카테고리의 다른 글

Copy constructor(Deep copy, Shallow copy) in C++  (0) 2018.11.09
Inheritance and Overriding in C++ with simple example  (0) 2018.11.07
Encapsulation (getters and setters) in C++  (0) 2018.11.06
Reference in C++  (0) 2018.11.06
Class and Object in C++  (0) 2018.11.06