有一个带有隐式参数的模板类声明:
列表.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
更新的问题:
我从模板定义中删除了默认参数:
列表.h
template <typename Item, const bool attribute>
class List: public OList <item, attribute>
{
public:
List() : OList<Item, attribute> () {}
....
};
使用类 List 的第一个文件具有参数属性的隐式值的前向声明
分析1.h
template <typename T, const bool attribute = true>
class List; //OK
class Analysis1
{
void function(List <Object> *list); //OK
};
第二类使用类 List WITH 前向定义使用隐式值
分析2.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 WITHOUT 前向定义使用隐式值
分析2.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)
};