請看看這個代碼:派生類作爲默認參數克++
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;
}
編譯生成以下錯誤消息克++:
test.cpp: In function 'int main()':
test.cpp:25: error: default argument for parameter of type
'A<int>::base&' has type 'A<int>::derived'
的基本思想(使用派生類作爲默認值對於base-reference-type參數)在visual studio中工作,但不在g ++中。我必須將我的代碼發佈到大學服務器,然後用gcc編譯它。我能做什麼?有什麼我失蹤?
不解決錯誤,但你可以只寫'int f(base&arg = derived())'。 – kennytm 2010-04-16 13:23:31