LNK2019 在 class 声明和定义

LNK2019 in class declaration and definition

我知道有几个问题。我已经检查了 MSDN 页面上的 LNK2019 错误,但我似乎无法具体说明出现此错误的原因。

这是我的声明文件:

#ifndef _COLLEGE_H_
#define _COLLEGE_H_
#include"SVCQ.h"
#include"SVTT.h"
#include<vector>

class College
{
private:
    std::vector<SVCQ> listCQ;
    std::vector<SVTT> listTT;
protected:
    std::ostream& print(std::ostream & os) const;
    std::istream& input(std::istream& is, int size1, int size2);
public:
    College();
    ~College();

    //ouput, input
    friend std::ostream& operator<<(std::ostream& os, const College& obj);
    friend std::istream& operator>>(std::istream& is, College& obj);

        //some more functions

};

#endif

这是我的定义文件:

#include "College.h"


College::College()
{
}


College::~College()
{
}

std::ostream& College::print(std::ostream & os) const
{
    for (size_t it = 0; it < listCQ.size(); ++it)
    {
        os << listCQ[it];
    }

    for (size_t it = 0; it < listTT.size(); ++it)
    {
        os << listTT[it];
    }

    return os;
}

std::istream& College::input(std::istream& is, int size1, int size2)
{
    listCQ.resize(size1);
    listTT.resize(size2);

    std::cout << "\n-----------------ENTER LIST CQ-----------------:\n";
    for (size_t it = 0; it < listCQ.size(); ++it)
    {
        std::cout << "#" << it + 1 << std::endl;
        is >> listCQ[it];
        std::cout << std::endl;
    }

    std::cout << "\n-----------------ENTER LIST TT-----------------:\n";
    for (size_t it = 0; it < listTT.size(); ++it)
    {
        std::cout << "# " << it + 1 << std::endl;
        is >> listTT[it];
        std::cout << std::endl;
    }

    return is;
}
std::ostream& operator<<(std::ostream& os, const College& obj)
{
    return obj.print(os);
}
std::istream& operator>>(std::istream& is, College& obj)
{
    int size1 = 0, size2 = 0;
    std::cout << "ENTER QUANTITY OF CQ: ";
    is >> size1;
    std::cout << "\nENTER QUANTITY OF TT: ";
    is >> size2;
    std::cout << std::endl;
    return obj.input(is, size1, size2);
}

LNK2019 消息指出了我在受保护的 printinput 方法中的缺陷,但我在这里没有发现任何错误。谁能帮帮我?

这是 2 条 LNK2019 消息之一:

Error   2   error LNK2019: unresolved external symbol "class std::basic_istream<char,struct std::char_traits<char> > & __cdecl operator>>(class std::basic_istream<char,struct std::char_traits<char> > &,class SVTT &)" (??5@YAAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV01@AAVSVTT@@@Z) referenced in function "protected: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall College::input(class std::basic_istream<char,struct std::char_traits<char> > &,int,int)" (?input@College@@IAEAAV?$basic_istream@DU?$char_traits@D@std@@@std@@AAV23@HH@Z)   d:\Projects12382_giuaKi\bai2\College.obj bai2

错误消息说明了一切:

operator>>(std::istream&, SVTT&) 缺少定义。要么你没有定义它,要么你没有link它。