Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.iso-c++ > #2016

Linker Problem mit Template Class

From Henning Follmann <hfollmann@itcfollmann.com>
Newsgroups de.comp.lang.iso-c++
Subject Linker Problem mit Template Class
Date 2017-02-08 10:48 -0500
Organization Aioe.org NNTP Server
Message-ID <slrno9mfdh.2f3.hfollmann@smallapple.itcfollmann.com> (permalink)

Show all headers | View raw


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           | hfollmann@itcfollmann.com

Back to de.comp.lang.iso-c++ | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Linker Problem mit Template Class Henning Follmann <hfollmann@itcfollmann.com> - 2017-02-08 10:48 -0500
  Re: Linker Problem mit Template Class Stefan Reuther <stefan.news@arcor.de> - 2017-02-09 18:39 +0100

csiph-web