暗黙のパラメーターを持つテンプレート クラスの宣言があります。
List.h
template <typename Item, const bool attribute = true>
class List: public OList <item, attribute>
{
public:
List() : OList<Item, attribute> () {}
....
};
別のヘッダー ファイルでフロー フォワード宣言を使用しようとしました。
分析.h
template <typename T, const bool attribute = true>
class List;
しかし、G++ には次のエラーが表示されます。
List.h:28: error: redefinition of default argument for `bool attribute'
Analysis.h:43: error: original definition appeared here
暗黙的なパラメーターなしで前方宣言を使用する場合
template <typename T, const bool attribute>
class List;
コンパイラはこの構造を受け入れません
分析.h
void function (List <Object> *list)
{
}
次のエラーが表示されます (つまり、暗黙的な値を受け入れません)。
Analysis.h:55: error: wrong number of template arguments (1, should be 2)
Analysis.h:44: error: provided for `template<class T, bool destructable> struct List'
Analysis.h:55: error: ISO C++ forbids declaration of `list' with no type
更新された質問:
テンプレート定義からデフォルト パラメータを削除しました。
List.h
template <typename Item, const bool attribute>
class List: public OList <item, attribute>
{
public:
List() : OList<Item, attribute> () {}
....
};
クラス List を使用する最初のファイルには、パラメーター属性の暗黙的な値を持つ前方宣言があります
Analysis1.h
template <typename T, const bool attribute = true>
class List; //OK
class Analysis1
{
void function(List <Object> *list); //OK
};
クラス リストを使用する 2 番目のクラスは、暗黙の値を使用して前方定義を使用します。
Analysis2.h
template <typename T, const bool attribute = true> // Redefinition of default argument for `bool attribute'
class List;
class Analysis2
{
void function(List <Object> *list); //OK
};
クラス List を使用する 2 番目のクラスは、暗黙の値を使用した前方定義なし
Analysis2.h
template <typename T, const bool attribute> // OK
class List;
class Analysis2
{
void function(List <Object> *list); //Wrong number of template arguments (1, should be 2)
};