What is an example of constructor in C++?

C++ allows us to use the three constructor functions we have discussed in the same class. For example: class complex { int a , b; public: complex() // default constructor { a= 10; b=45; }; complex( int x, int y) // parameterized constructor { a=x; b=y; }; complex( complex & v) // copy constructor { a=v.a; b=v.b; }; };

Sizin İçin Seçtik  What is a class constructor in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *