请看一下这段代码:
template<class T>
class A
{
class base
{
};
class derived : public A<T>::base
{
};
public:
int f(typename A<T>::base& arg = typename A<T>::derived())
{
return 0;
}
};
int main()
{
A<int> a;
a.f();
return 0;
}
编译在 g++ 中生成以下错误消息:
test.cpp: In function 'int main()':
test.cpp:25: error: default argument for parameter of type
'A<int>::base&' has type 'A<int>::derived'
基本思想(使用派生类作为基本引用类型参数的默认值)在 Visual Studio 中有效,但在 g++ 中无效。我必须将我的代码发布到他们用 gcc 编译的大学服务器。我能做些什么?有什么我想念的吗?