我正在尝试构建一个类模板,一切看起来都很好,但是每当我尝试运行代码时,我都会遇到这个错误“Un defined reference to'Yonah::Yonah(int,int)‘”
这里是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号,是我的代号。
'''
#include <iostream>
using namespace std;
template<class T>
class Yonah
{
T first, second;
public:
Yonah(T a, T b);
T larger();
} ;
template<class T>
T Yonah<T>::larger()
{
return(first>second?first:second);
}
int main()
{
Yonah <int> obj(4,5);
cout<<"Larger = "<<obj.larger();
return 0;
}
'''
您忘记实现构造函数,如下所示:
template<class T>
class Yonah
{
T first, second;
public:
Yonah(T a, T b): first(a), second(b) {}
T larger();
} ;