Turns out I need to build a function that takes a variable number of arguments of no predetermined types,something like:
myFun(int param1, char param2, short param3....);
And I thought about using variadic template functions. This is actually a member function of a class which is inside a namespace, this is my header file:
//USART.hh file
namespace usartNameSpace
{
class USART
{
public:
USART();
~USART();
template <typename firstArgument, typename ...Arguments> bool parseUserCommands(firstArgument &argument, Arguments &... args);
};
}
This is the implementation(I have omitted both the constructor and destructor)
//USART.cpp file
using namespace usartNameSpace;
template <typename firstArgument, typename ...Arguments> bool USART::parseUsercommands(firstArgument &argument, Arguments&... args)
{
//stuff the function does
}
I will say it again, my goal is to be able to create a method that takes a variable number of parameters of no particular type, with this conception I think I'm able to reach that, however, when calling the method from the main.cpp file, I get the following error at compile time:
undefined reference to `bool usartNameSpace::USART::parseUserCommands<int, char>(int&, char&)'
collect2: error: ld returned 1 exit status
make: *** [makefile:68: mainProject.elf] Error 1
I do not really know what is wrong with my conception of things here, someone told me to try to put the implementation in the same header where the definition lies but that did not work neither(If someone could explain this one also, it would be very nice).
Lastly, here is my main file:
#include "USART.hh"
usartNameSpace::USART coms(USART2);
int n = 8;
char m = 'a';
int main(void)
{
coms.parseUserCommands<int, char>(n, m);
return 0;
}