1
下面的代碼編譯沒有任何錯誤:C++ 11名decltype和數據成員
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'
我在做什麼錯?我該如何解決它?
鐺++ 3.5和g ++ 4.8.1接受它。這是一個強烈的暗示,這是MSVC中的一個錯誤。 – dyp
我認爲這是MSVC中的一個錯誤。 * trailing-return-type *不是* declarator-id *的一部分,但是在它後面。因此,名稱查找是(=應該)與* inside *成員函數主體的定義相同。 – dyp