Chr*_*ris 0 c++ initialization copy-initialization
为什么以下代码无法编译,而编译成功后的两个示例?我在Windows 7上使用VS 2008.
直接初始化POD(失败):
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 &'
Run Code Online (Sandbox Code Playgroud)
复制POD的初始化(成功:
int pod = int();
std::vector<int> pods;
pods.push_back(pod); // No error!
Run Code Online (Sandbox Code Playgroud)
查找" 最令人烦恼的解析 "(这里也一遍又一遍地讨论过).
int pod(); // this does not declare (nor define) an integer
Run Code Online (Sandbox Code Playgroud)
顺便问一下,你为什么把它1
放在MyClass例子中?