错误:"模板<类 T>类 2"在没有模板参数的情况下使用

Error: 'template<class T> class Two' used without template parameters

本文关键字:参数 情况下 lt 模板 gt 错误      更新时间:2023-10-16

嘿,我试着编译:

//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)

相关文章: