gpt4 book ai didi

c++ - 错误 : 'template class Two' used without template parameters

转载 作者:行者123 更新时间:2023-11-30 02:54:49 25 4
gpt4 key购买 nike

嘿,所以我正在尝试编译:

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

并在需要的地方进行类似的更改。

关于c++ - 错误 : 'template<class T> class Two' used without template parameters,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16823922/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com