#include<iostream>
using namespace std;
class C{
private:
int value;
public:
C(){
value = 0;
cout<<"default constructor"<<endl;
}
C(const C& c){
value = c.value;
cout<<"copy constructor"<<endl;
}
};
int main(){
C c1;
C c2 = C();
}
Output:
default constructor
default constructor
Question:
For C c1;
default constructor will be called obviously, for C c2 = C();
I thought default constructor will be called to initialize a temporary object, then copy constructor will be call to initialize c2, It seems that I am wrong. why?