【发布时间】:2016-08-15 08:01:00
【问题描述】:
我在Cpp Quiz 看到了一个代码 [问题 #38]
#include <iostream>
struct Foo
{
Foo(int d) : x(d) {}
int x;
};
int main()
{
double x = 3.14;
Foo f( int(x) );
std::cout << f.x << std::endl;
return 0;
}
据说这段代码格式不正确,因为Foo f( int(x) ); 将被视为函数声明,而不是Foo 类型的对象声明。
据我所知,这是“最令人头疼的解析”的一个实例。我的问题是语句Foo f( int(x) ); 中的这种语法int(x) 是什么意思?到目前为止,我只看到如下函数声明:
-
Foo f( int );和 -
Foo f( int x );
和Foo f( int x );一样吗?
【问题讨论】:
标签: c++ most-vexing-parse