Take a look at the following code:
class Test
{
public:
Test()
{
cout << "default\n";
}
Test(const Test&)
{
cout << "copy\n";
}
Test& operator = (const Test&)
{
cout << "assign\n";
return *this;
}
};
int main()
{
Test t = Test();
}
Which constructor should be called in the main function?
I run and it prints "default" and nothing else. However, if I make the copy constructor and assignment operator private, it doesn't compile. But it wasn't using that constructor any way.
Which constructor should be used? Is it guaranteed by standard? Is this some rule I didn't know about?
Live code examples: