没有参数列表的模板名称'x'使用无效
invalid use of template-name 'x' without an argument list
当试图使用C++从Stroustrup的编程原理和实践中编译一个示例程序时,出现了这个问题。我在第12章,他开始使用FLTK。我在图形和GUI支持代码中遇到编译器错误。特别是图h第140和141行:
error: invalid use of template-name 'Vector' without an argument list
error: ISO C++ forbids declaration of 'parameter' with no type
template<class T> class Vector_ref {
vector<T*> v;
vector<T*> owned;
public:
Vector_ref() {}
Vector_ref(T& a) { push_back(a); }
Vector_ref(T& a, T& b);
Vector_ref(T& a, T& b, T& c);
Vector_ref(T* a, T* b = 0, T* c = 0, T* d = 0)
{
if (a) push_back(a);
if (b) push_back(b);
if (c) push_back(c);
if (d) push_back(d);
}
~Vector_ref() { for (int i=0; i<owned.size(); ++i) delete owned[i]; }
void push_back(T& s) { v.push_back(&s); }
void push_back(T* p) { v.push_back(p); owned.push_back(p); }
T& operator[](int i) { return *v[i]; }
const T& operator[](int i) const { return *v[i]; }
int size() const { return v.size(); }
private: // prevent copying
Vector_ref(const Vector&); <--- Line 140!
Vector_ref& operator=(const vector&);
};
完整的标题和相关的图形支持代码可以在这里找到:
http://www.stroustrup.com/Programming/Graphics/
除了代码修复之外,有人能用通俗的英语解释一下这里发生了什么吗。我才刚刚开始研究模板,所以我有一些模糊的想法,但它仍然遥不可及。感谢您,
Vector_ref(const Vector&); <--- Line 140!
参数类型应为Vector_ref
,而不是Vector
。有一个打字错误。
Vector_ref& operator=(const vector&);
这里的参数应该是vector<T>
。你忘了提到类型参数。
但读到这条评论,我相信这也是一个拼写错误。你也不是说vector<T>
。你的意思是:
// prevent copying
Vector_ref(const Vector_ref&);
Vector_ref& operator=(const Vector_ref&);
在C++0x中,可以执行以下操作来防止复制:
// prevent copying
Vector_ref(const Vector_ref&) = delete; //disable copy ctor
Vector_ref& operator=(const Vector_ref&) = delete; //disable copy assignment
相关文章:
- 为什么 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++ 无效参数错误
- 搜索无效参数