C++ C++;,比较器和模板
tis代码中有什么错误C++ C++;,比较器和模板,c++,templates,comparator,C++,Templates,Comparator,tis代码中有什么错误 template <typename T, template <typename> class GList> struct TSet { typedef std::set <unsigned int, sortIndices <T, GList> > Type; //Error, too many template arguments }; template <typename T, template
template <typename T, template <typename> class GList>
struct TSet
{
typedef std::set <unsigned int, sortIndices <T, GList> > Type; //Error, too many template arguments
};
template <typename T, template <typename> class GList>
class sortIndices
{
private:
const GList <T> *l;
public:
sortIndices ( const GList <T> *l_ ) : l ( l_ ) {}
bool operator() ( const unsigned int &i_p1, const unsigned int &i_p2 ) const
{
...
}
};
模板
结构TSet
{
typedef std::set Type;//错误,模板参数太多
};
模板
类别分类
{
私人:
常量GList*l;
公众:
sortIndices(const GList*l_uu):l(l_u){
布尔运算符()
{
...
}
};
它编译得很好。您需要做的就是:在排序之后定义TSet
你自己看看:使用
::Type
:的示例,您得到的确切错误是什么?它指的是哪条线?实例化堆栈是什么?这个代码有什么问题?它不编译吗?它没有达到您期望的效果吗?另外,在TSet
的定义中,是否有sortIndices
的声明?您用什么来实例化此模板?看起来错误可能是您试图用错误的参数实例化模板。@Jeremiah:谢谢。我也拿走了我的。:-)添加时未编译:在main()
@Pawel Zubrycki:Ohh.中键入。。这就是为什么你否决了它?如果你知道这两个例子说明了两件不同的事情?不管怎样,我已经编辑了我的帖子。现在查看使用main()中的:Type
。@Pawel Zubrycki。隐马尔可夫模型。。。然后其他人给出了答案,但没有说明原因。也许他读了你的评论:P