dimanche 29 novembre 2015

C++ templates and friends, linker error

Why does the following code not compile (linker error, unresolved external symbol, class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class cClass<int> const &)" (??6@YAAEAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AEAV01@AEBV?$cClass@H@@@Z))

#include <iostream>

template <class Type> class Class{
    public:
        friend std::ostream& operator<<(std::ostream& Stream, const Class& Op);
};

template <class Type> std::ostream& operator<<(std::ostream& Stream, const Class<Type>& Op){
    return(Stream);
}

int main(){
    Class<int> A;

    std::cout << A;

    return(0);
}

Aucun commentaire:

Enregistrer un commentaire