Show activity on this post. int main() int *a; a=new int[4]; for(int i=0;i<5;i++){ a[i]=i; cout<<a[i]<<endl; } Array array1(a);//Constructor invoked array1. Print(); Array another=array1;//copy constructor invoked another. Print();
Read moreHow do I copy an entire array in C++?
Copy an Array in C++
Read moreWhat are copy constructors in C++?
The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously . The copy constructor is used to − Initialize one object from another of the same type. Copy an object to pass it as an argument to a function.
Read moreWhy do we need to overload a constructor in C++?
Answer: Benefits of constructor overloading in C++ is that, it gives the flexibility of creating multiple type of objects of a class by having more number of constructors in a class , called constructor overloading. In fact, it is similar to C++ function overloading that is also know as compile time polymorphism.
Read more