Search code examples
c++visual-studioclasslnk2019

LNK2019 in class declaration and definition


I know there are several questions on this. I have checked the MSDN page for LNK2019 error but I can not seem to specify why this error appeared.

This is my declaration file:

#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

And this is my definition file:

#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);
}

The LNK2019 messages specify my flaws in the protected print and input method but I don't see anything wrong here. Can anyone help me?

Here's one of 2 LNK2019 messages:

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

Solution

  • The error message says it all:

    operator>>(std::istream&, SVTT&) is missing a definition. Either you didn't define it, or you didn't link it.