Why does the following code fail to compile, while the two examples after compile successfully? I'm using VS 2008 on Windows 7.
Direct initialization of POD (fails):
int pod();
std::vector<int> pods;
//pods.push_back(pod); // This will generate a compiler error
// Compile error: 1>c:\test.hpp(43) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'int (__cdecl *)(void)' to 'const int &'
Copy initialization of POD (succeeds:
int pod = int();
std::vector<int> pods;
pods.push_back(pod); // No error!
Look up "most vexing parse" (it has been discussed over and over again here, too).
By the way, why did you put that
1
in the MyClass example?