#include<iostream>
using namespace std;
class A {
int k;
int *ptr;
public:
A(int a):k(a) {
cout<<"ctor\n";
ptr = new int[k];
for(int i = 0; i < k; i++) {
*(ptr + i) = i*i*i;
}
}
A(const A &obj) {
cout<<"copy ctor\n";
k == obj.k;
ptr = new int[k];
for(int i = 0; i < k; i++) {
*(ptr + i) = i*i;
}
}
void show() {
for(int i = 0; i < k; i++) {
cout<<*ptr++<<" ";
}
}
};
A foo() {
A temp(5);
return temp;
}
int main() {
A obj = foo();
obj.show();
return 0;
}
** The temp object returned by foo() is not copied. Normal constructor is called in this but not copy constructor. Can anyone point where exactly I am going wrong.**