lia*_*iaK 3 c++ most-vexing-parse
基本上这是关于最烦恼的解析的这个问题的后续.我可以理解这是由于函数声明和变量定义之间的模糊性.
但在Comeau在线,我只是厌倦了以下.
class T{
public:
T(int i){
}
int fun1(){
return 1;
}
};
int main()
{
T myT(10); // I thought it'd be a function declaration that takes an int and returns a type T
myT.fun1(); // and a compiler error out here.
}
Run Code Online (Sandbox Code Playgroud)
但它编译得很好而且没有错误.我查看了标准文档但无法进行推理.
那么,我在这里错过了什么?
因为10不是一种类型.:)
这将是一个最令人烦恼的解析:
T myT(T());
// T() gets interpreted as function pointer argument to a function returning T();
// This is equivalent to:
T myT(T (*fn)());
Run Code Online (Sandbox Code Playgroud)
另一种最令人烦恼的解析是这一个:
unsigned char c = 42;
T myT(int(c));
// int(c) gets interpreted as an int argument called c.
// This is equivalent to:
T myT(int c);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
208 次 |
| 最近记录: |