0

I'm trying to use a function in a class that accepts a function pointer to any function of any class that is included in my file. Here is my attempt using a variadic template:

In Object.cpp:

#include "aClass.h"

template <class C, typename T0, typename... T> unsigned char* Object::myFunction(T0 (C::*inputFunc)(T... argList)) {
    //function body
    return anUnsignedCharPtr;}

In main.cpp:

#include "Object.h"

Object someObject = Object();
void (aClass::*inputFunc)(int);
inputFunc = &(aClass::aFunction);
unsigned char* anUnsignedCharPtr = someObject.myFunction(inputFunc);

When I try to compile with MVS 2013 I get the following error: "error LNK2019: unresolved external symbol...". What am I doing wrong?

TylerKehne
  • 361
  • 2
  • 12
  • Also: parenthesis aren't needed to get aFunction's address. But chris is right: that function is into another translation unit, I missed it big time. – Marco A. Aug 28 '14 at 19:25
  • Yup, moved the definition to the header and it works now. Thanks. – TylerKehne Aug 28 '14 at 19:28
  • @chris Make it an answer, just for completion. – Marco A. Aug 28 '14 at 19:29
  • 1
    @MarcoA., Eh, I realized it really is a dupe of [this answer](http://stackoverflow.com/a/12574417/962089). Also related: http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – chris Aug 28 '14 at 19:31

0 Answers0