samedi 2 mars 2019

Unresolved external symbol [C++] [duplicate]

So, i have the following code, and i cant figure out why i get this error :

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "int __cdecl first(class _PairWrapper &)" (?first@@YAHAAV?$_PairWrapper@HM@@@Z) referenced in function _main mapCustomIterator C:\Users\Daniel\source\repos\mapCustomIterator\mapCustomIterator\Source.obj 1

The code:

#include <iostream>

namespace std {

template<typename T, typename T1>
class _PairWrapper;

template<typename T, typename T1>
T first(_PairWrapper<T, T1> &aPair);

template<typename T, typename T1>
class _PairWrapper {
public:
    _PairWrapper() = default;
    _PairWrapper(T initVal, T1 initVal2) {
        container = initVal;
        container1 = initVal2;
    }
    ~_PairWrapper() {
        cout << "Pair deleted" << endl;
    }
    friend T first(_PairWrapper<T, T1> &aPair);
    friend T1 second(_PairWrapper<T, T1> &aPair);
private:
    T container;
    T1 container1;
};

template<typename T, typename T1>
T first(_PairWrapper<T, T1> &aPair) {
    return aPair.container;
}

template<typename T, typename T1>
T1 second(_PairWrapper<T, T1> &aPair) {
    return aPair.container1;
}

}

using namespace std;

int main() {

_PairWrapper<int, float> obj(5, 3);

first(obj);

return 0;

}

Aucun commentaire:

Enregistrer un commentaire