0

I am trying to create a method that allows for a variable number of inputs. I was trying to implement this answer (see the code below) however, I got an error when I tried to run my code.

Code

header:

template<typename T, typename... Args>
void vSend ( T tIn, Args... AArgs );
template <typename T>
void vSend ( T tIn );

CPP

template<typename T, typename... Args>
void Connector::vSend ( T tIn, Args... AArgs )
{
    pPacketToSend << tIn;

    vSend(AArgs...);
}

template <typename T>
void Connector::vSend ( T tIn )
{
    pPacketToSend << tIn;

    tSocket.send(pPacketToSend);
}

Error

Undefined symbols for architecture x86_64:
  "void Connector::vSend<int, int>(int, int)", referenced from:
      Updater::Update(sf::Image*) in updatedirector.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Edit (Answer)

Turns out templates may only be implemented in the header file.

zoecarver
  • 5,523
  • 2
  • 26
  • 56

0 Answers0