jeudi 3 août 2017

Templated method in pure abstract class

Context:

I have a pure abstract class where all methods are virtual and =0. This class is to be defined as a pointer and a class that inherits and has the actual implementation is to be std::moved into the pointer.

Problem:

I'd like to add a templated method to the pure abstract class so users of this class can pass the return type and thus avoid creating a large number of getters:

template <typename T = std::string>
T value(const uint32_t column, const uint32_t row) const;

But this does not work. When compiling with gcc 4.8.5 I get the following error in my unit tests:

Undefined symbols for architecture x86_64:
  "int databaseclient::internal::AbstractResult::value<int>(unsigned int, unsigned int) const", referenced from:
      ____C_A_T_C_H____T_E_S_T____0()      in state_machines.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Is there anything specific that needs to be done to add a templated method to a pure abstract class?

Aucun commentaire:

Enregistrer un commentaire