C++ 在没有参数列表的情况下,模板名称的使用无效
这是我的代码,我一直收到错误。/partition2.h:45:5:error:在没有参数列表的情况下,模板名“fsu::partition2”的使用无效,但我不确定是什么导致了此错误。通常是因为我没有把模板放在函数之前,但现在我有点困惑了C++ 在没有参数列表的情况下,模板名称的使用无效,c++,templates,C++,Templates,这是我的代码,我一直收到错误。/partition2.h:45:5:error:在没有参数列表的情况下,模板名“fsu::partition2”的使用无效,但我不确定是什么导致了此错误。通常是因为我没有把模板放在函数之前,但现在我有点困惑了 #include "vector.h" #include <vector> #include <cstdlib> #include <iostream> #include <iomanip> #include
#include "vector.h"
#include <vector>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <entry.h>
#include <list.h>
#include <primes.h>
namespace fsu
{
template < typename N = size_t >
class Partition2
{
public:
explicit Partition2 ( N size ); // create singletons {0} .. {size-1}
void Reset (); // reverts to singletons
void Reset ( N newsize );
void PushSingleton () { parent_.PushBack((N)parent_.Size()); rank_.PushBack(0); }
void Union ( N x , N y ) { Link(Root(x),Root(y)); }
bool Find ( N x , N y ) { return Root(x) == Root(y); }
bool Find ( N x , N y ) const { return Root(x) == Root(y); }
size_t Size () const { return rank_.Size(); }
size_t Components () const;
void Display ( std::ostream& os ) const;
void Dump ( std::ostream& os ) const;
private: // methods
N Root ( N x ); // path compression changes state
N Root ( N x ) const; // no path compression
void Link ( N root1 , N root2 ); // union assuming arguments are roots
private: // objects
fsu::Vector <N> parent_;
fsu::Vector <N> rank_;
N comp_count;
};
template < typename N = size_t >
Partition2::Partition2 ( N size) : parent_((size_t)size,0), rank_((size_t)size, 0)
{
}
} //fsu
#包括“vector.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括
名称空间fsu
{
模板
班级划分2
{
公众:
显式分区2(N size);//创建单例{0}..{size-1}
void Reset();//恢复为单例
无效重置(N新闻大小);
void PushSingleton(){parent.PushBack((N)parent.Size());rank.PushBack(0);}
无效并集(nx,ny){Link(根(x),根(y));}
boolfind(nx,ny){返回根(x)=根(y);}
布尔查找(nx,ny)常数{返回根(x)=根(y);}
size_t size()常量{return rank_u.size();}
尺寸组件()常数;
无效显示(标准::ostream&os)常数;
无效转储(标准::ostream&os)常数;
私有方法
N根(nx);//路径压缩更改状态
N Root(nx)const;//无路径压缩
void Link(N root1,N root2);//假定参数为根的并集
私有对象
向量父函数;
向量秩;
N comp_计数;
};
模板
分区2::分区2(N个大小):父级大小((大小)大小,0),秩大小((大小)大小,0)
{
}
}//fsu
对于类模板成员的越界定义,需要在类名后添加模板参数
template < typename N = size_t >
Partition2<N>::Partition2 ( N size) : // ...
{
// ...
}
template
分区2::分区2(N大小):/。。。
{
// ...
}
顺便说一句,我不建议使用
N
作为类型模板参数的名称,因为它通常用于整型(非类型)模板参数。您能指出哪一行是第45行吗-_-“那么,您应该给模板一个模板参数列表吗?