没有参数列表的模板名称使用无效
invalid use of template-name w/o an argument list
这是我的代码,我不断收到错误./partition2.h:45:5:错误:在没有参数列表的情况下无效使用模板名称"fsu::P artition2",但我不确定是什么导致了此错误。通常是因为我没有在我的函数之前放置模板,但现在我有点困惑。
#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
对于类模板成员的外联定义,需要在类名后使用模板参数。
template < typename N = size_t >
Partition2<N>::Partition2 ( N size) : // ...
{
// ...
}
顺便说一句,我不建议使用 N
作为类型模板参数的名称,因为它通常用于整型(非类型)模板参数。
相关文章:
- 为什么 CRTP 模板C++给出无效参数错误?
- 为什么此字符串在传递到stoi时被视为无效参数
- boost::asio::async_write无效参数
- C ++回测问题:如何检查构造函数在假定失败时是否失败(给定输入的无效参数)
- 无效参数 C++ cygwin
- 套接字接受无效参数 (c++)
- 从带有 getline() 的文件读入一行上有多个信息得到无效参数错误
- 将无效参数传递给将无效参数视为致命的函数
- 如何避免字符串到整数转换情况下的无效参数异常
- 张量流 无效参数:In[0] 不是矩阵
- cudaFreeHost() 无效参数错误
- 未经治疗的例外,无效的参数传递给了一个认为无效参数作用的函数
- C++带有可变参数模板的无效参数
- std::find是否隐式修复无效参数
- 为什么这个程序告诉我传递了无效参数
- 在Win32中获取SetConsolecursorPosition函数的ERRORRORNO 87(无效参数)
- MSVCR120.dll的无效参数错误(在64位窗口中构建Tesseract Lib)
- 在C++中使用字符串类的 .substr 获取无效参数
- MySQL++ 无效参数错误
- 搜索无效参数