我不明白下面的问题。
class InnerBox
{
public:
InnerBox() : mContents(123) { };
private:
int mContents;
};
class Box
{
public:
Box(const InnerBox& innerBox) : mInnerBox(innerBox) { };
private:
InnerBox mInnerBox;
};
void SomeFunction(const Box& box)
{
return;
}
int main()
{
Box box(InnerBox()); // !!PROBLEM!! Doesn't work: compiler thinks this is a function declaration
SomeFunction(box); // Error, cannot convert 'function pointer type' to const Box&
return 0;
}
完整的错误消息是(Visual Studio 2010)
error C2664: 'SomeFunction' : cannot convert parameter 1 from 'Box (__cdecl *)(InnerBox (__cdecl *)(void))' to 'const Box &'
修复很简单:
int main()
{
InnerBox innerBox;
Box box(innerBox);
SomeFunction(box);
return 0;
}
这是一个 MSVC 特有的问题吗?如果不是,有人可以解释该语言的哪些怪癖阻止我打电话Box box(InnerBox());
吗?