下面的代碼片段失敗,Visual Studio 2010中編譯,但GCC喜歡它:在命名空間中轉發定義類?
namespace Test {
class Baz;
// Adding class Bar; here and removing the class below makes it work
// with VC++, but it should work like this, shouldn't it?
void Foo (Baz& b, class Bar& c);
}
namespace Test {
class Bar
{
// Making this method non-template works
template <typename T>
static void Lalala()
{
}
};
}
int main()
{
}
我做一些愚蠢的事在這裏還是這是一個有效的編譯器錯誤?我得到的錯誤是: error C2888: 'void Bar::Foo(void)' : symbol cannot be defined within namespace 'Test'
它編譯使用GCC 4.5.1:http://ideone.com/7sImY
[編輯]只是要清楚,我想知道這是否是有效的C++或沒有(如果是這樣,爲什麼不是) - 解決方法讓它編譯好,但不是這個問題的一部分。
OP在問題中說GCC編譯它,MSVC沒有。 –
有時允許使用'class Bar'作爲類型。避免這種情況通常是個好主意,因爲「有時」很複雜。 – aschepler
它編譯GCC _as現在_(GCC 4.5.1和GCC4.6.1),所以這沒有幫助。 – Anteru