Ich habe hier ein Problem beim Linken mit einer template class. Ich habe
einmal ein vereinfachtes Beispiel zusammengestellt:
printer.hpp
====================================
#ifndef _PRINTER_HPP_INCLUDE_
#define _PRINTER_HPP_INCLUDE_
#include <iostream>
template <typename T1>
class printer{
std::ostream& _out;
public:
printer(std::ostream& os):_out{os} {};
void operator()(T1 var);
};
#endif
====================================
printer.cpp
====================================
#include "printer.hpp"
template <typename T1>
void printer<T1>::operator()(T1 var){
_out<<var<<"\n";
}
====================================
maintest.cpp
====================================
#include <iostream>
#include "printer.hpp"
int main()
{
printer<int> prntr{std::cout};
prntr(25);
return 0;
};
====================================
Die Uebersetzung schlaegt fehl. Genauer gesagt, die Bindung:
g++ -std=c++11 maintest.cpp printer.cpp
/tmp/ccRR5tP2.o: In function `main':
maintest.cpp:(.text+0x26): undefined reference to
`printer<int>::operator()(int)'
collect2: error: ld returned 1 exit status
Ist das ein Fehler des Linkers?
Gruss
Henning
--
Henning Follmann |
hfol...@itcfollmann.com