I'm really confused.... does Type t = Type()
call the copy constructor or no?
I'm asking because when I try:
#include <iostream>
class Test
{
public:
Test(Test const &) { std::cout << "hello"; }
Test() { }
};
int main()
{
Test t = Test();
return 0;
}
nothing is output, but when I change it to
#include <iostream>
class Test
{
Test(Test const &) { std::cout << "hello"; }
public:
Test() { }
};
int main()
{
Test t = Test();
return 0;
}
I get:
error C2248: 'Test::Test' : cannot access private member declared in class 'Test'
which doesn't make sense (especially since this is a debug build).
Update:
Even this compiles!
struct Test
{
Test(Test &&) = delete;
Test(Test const &) = delete;
Test() { }
};
int main()
{
Test t = Test();
return 0;
}
So is a copy/move constructor necessary or no?