次のスニペットはVisualStudio2010でコンパイルできませんが、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 ++であるかどうか(もしそうなら、なぜそうではないか)を知りたいのですが、コンパイルするための回避策は素晴らしいですが、この質問の一部ではありません。