このようなクラスを作成しました。重要なのは、メインのテンプレート引数と、デフォルトのテンプレート基本クラスがあることです。テンプレート化されたコピーコンストラクターもあります...
struct default_base{};
template <typename T, typename TBase=default_base>
class some_class : public TBase{
public:
some_class(){}
template <typename U, typename UBase>
some_class(const some_class<U,UBase>& u){
T t(U());
}
};
int main(){
some_class<int> a;
return 0;
}
このうっとうしい漠然としたコンパイラ エラーが発生し、エラーを見つけることができませんでした。gcc 4.8.1 を使用しています。
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\stuff.o" "..\\src\\stuff.cpp"
..\src\stuff.cpp: In constructor 'some_class<T, TBase>::some_class(const some_class<U, UBase>&)':
..\src\stuff.cpp:87:10: error: default argument for template parameter for class enclosing 'T t(U (*)())'
T t(U());
^
..\src\stuff.cpp: In function 'int main()':
..\src\stuff.cpp:104:16: error: wrong number of template arguments (1, should be 2)
some_class<int> a;
^
..\src\stuff.cpp:82:7: error: provided for 'template<class T, class TBase> class some_class'
class some_class : public TBase{
^
..\src\stuff.cpp:104:19: error: invalid type in declaration before ';' token
some_class<int> a;
編集:答えを見つけてください、乾杯:-)それでもコンパイルする必要があると思っていても...これはコンパイルされます...
template <typename T>
struct some_other_class{
some_other_class(){}
template <typename U>
some_other_class(){
T t(U());
}
};