LNK2019在类声明和定义中

时间:2015-11-01 02:55:18

标签: c++ visual-studio class lnk2019

我知道有几个问题。我已经检查了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消息在受保护的打印输入方法中指定了我的缺陷,但我在这里看不到任何错误。任何人都可以帮助我吗?

此处是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:\Projects\1412382_giuaKi\bai2\College.obj bai2

1 个答案:

答案 0 :(得分:0)

错误消息说明了一切:

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