错误:"模板<类 T>类 2"在没有模板参数的情况下使用
Error: 'template<class T> class Two' used without template parameters
嘿,我试着编译:
//ASSIGNMENT
#include <iostream>
#include <string>
using namespace std;
template <class T>
class Two {
private: T x,y;
public:
Two (T a, T b);
friend void Show (Two p);
~Two();
};
//ASSIGNMENT
template <class T>
Two::Two (T a, T b){
x = a;
y = b;
}
friend void Two::Show(Two p){
cout << p.x << " and " << p.y << endl;
}
int main () {
Two<int> class2(2,3);
Show(class2);
}
赋值是用来定义类的成员(在//assignment标记中)。我不知道为什么它不能编译…谢谢!
变化
template <class T>
Two::Two (T a, T b)
template <class T>
Two<T>::Two (T a, T b)
相关文章:
- 在没有参数列表的情况下使用模板名称"Event"无效,模板问题
- 在不传递参数数量且只有3个点的情况下,如何使用变差函数
- G++ C++17 类模板参数推导在非常特殊的情况下不起作用
- 如何在不知道C++中有多少可选参数的情况下在循环中使用va_arg?
- 如何在不强制转换每个参数的情况下删除初始值设定项列表中从 int 到 char 的缩小转换?
- 如何在不使用指针的情况下将派生类的对象作为参数传递给基类中的函数?
- 如何在不传递命令行参数的情况下在 c++ 中设置环境变量
- C++有什么方法可以在既不调用函数模板也不提供其模板参数的情况下引用函数模板?
- 是否可以在不填充自己的参数的情况下将模板函数作为参数传递?
- 我应该如何在没有变量的情况下将相同的参数传递给 CMAKE 中的多个目标?
- 是否可以在不扣除的情况下将模板参数转发到 make_*?
- 为什么或在什么情况下,你会将参数作为C++中的引用(或指针)传递给函数?
- 如何在给定 std::variant 的情况下检索模板参数包?
- 在C++中,有没有一种方法可以让我在不传递参数的情况下拥有一个函数
- 如何在没有参数包的情况下编写变差函数
- 如何在不使用文件扩展名的情况下使用命令行参数打开C++中的文本文件?
- 此函数如何在不传递任何参数的情况下工作?
- 在什么情况下,使用'const T*'输入参数比'const T&'更可取?
- 如何在没有可变参数函数的情况下循环函数的参数
- 是否有可能在没有复制的情况下传递 std::vector<int> 作为参数来获得 std::vector<std::array<int, 3>>?