提问者:小点点

如何解决C++中“未定义引用”错误


我正在尝试构建一个类模板,一切看起来都很好,但是每当我尝试运行代码时,我都会遇到这个错误“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;
}

'''


共1个答案

匿名用户

您忘记实现构造函数,如下所示:

template<class T>
class Yonah
{
    T first, second;
    public:
        Yonah(T a, T b): first(a), second(b) {}
        T larger();

} ;

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(解决|c++|中|未定义|引用)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?