1

I'm getting an undefined reference for this call:

Argonauts::Runtime::handleParseObject(m_val.m_type)

The handleParseObject function is defined in a header included by the file containing the above line like this (inside the Argonauts::Runtime namespace):

template <typename Type> HandleParseAction handleParseObject(Type &) { return HandleParseAction("Unexpected value of type 'object'"); }

Overloads of function exist, this templated one should be a fallback for any type that does not have an overloaded variant.

The error message:

undefined reference to `Argonauts::Runtime::HandleParseAction Argonauts::Runtime::handleParseObject<SiteType>(SiteType&)'

Searching for help, both on SO and using Google is pretty much useless, since all results are from people who put the definition of the template function inside a source file.

I can get rid of the error by making the function static, but I feel uneasy about this. Is this the right way to do it or are there better ways?

Jan
  • 993
  • 1
  • 13
  • 28
  • Does exist an overload or specialization for the type of `SiteType&`? My guess is that an overload is declared but not defined. – Paolo M Aug 28 '15 at 15:28
  • `m_type` is a member of `m_val` of type `SiteType`. There is neither overload nor specialization for this, thus the templated fallback should be called. – Jan Aug 28 '15 at 15:30
  • Maybe the compiler is confused by the infinite recursion. I expect you have an infinite recursion because you think a quoted string is a `char const*` but in fact it isn't. I expect you have an overload for `char const*` so if you cast the quoted string to a `char const*` it should work. – JSF Aug 28 '15 at 15:32
  • Infinite recursion? Where? – Jan Aug 28 '15 at 15:34
  • 2
    Please post an [MCVE](http://stackoverflow.com/help/mcve). – R Sahu Aug 28 '15 at 15:34
  • 1
    Turns out it was just me being stupid, I had accidentally left a declaration for the overload in one place, so it tried picking that one... – Jan Aug 28 '15 at 16:03
  • look at https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file?rq=1 – Amir Mar 21 '19 at 23:19

0 Answers0