【发布时间】:2014-02-26 16:24:02
【问题描述】:
以下代码编译没有任何错误:
class foo
{
public:
void some_func() {}
};
class bar
{
private:
foo instance;
public:
auto some_func() -> decltype(instance.some_func()) {}
};
int main() {}
虽然以下代码无法在 MSVC-12.0 中编译:
class foo
{
public:
void some_func() {}
};
class bar
{
private:
foo instance;
public:
auto some_func() -> decltype(instance.some_func());
};
auto bar::some_func() -> decltype(instance.some_func()) {}
int main() {}
它给了我以下错误:
error C2228: left of '.some_func' must have class/struct/union
error C2556: 'int bar::some_func(void)' : overloaded function differs only by return type from 'void bar::some_func(void)'
: see declaration of 'bar::some_func'
error C2371: 'bar::some_func' : redefinition; different basic types
: see declaration of 'bar::some_func'
我做错了什么?我该如何解决?
【问题讨论】:
-
clang++3.5 和 g++4.8.1 接受它。这是一个强烈的暗示,它是 MSVC 中的一个错误。
-
我认为这确实是 MSVC 中的一个错误。 trailing-return-type 不是 declarator-id 的一部分,而是跟随它。因此,名称查找是(=应该)与inside成员函数体的定义相同。