Copy Constructor
void func(MyClass a) {
}
int main() {
MyClass myClass;
// below, a shallow copy of myClass is created and supplied to func(MyClass a)
func(myClass);
return 0;
}MyClass func() {
MyClass myClass;
// below, a shallow copy of myClass is created and supplied back to caller, i.e. main()
return myClass;
}
int main() {
MyClass myClass = func();
return 0;
}Example:
Key points about copy constructors:
Last updated