First of all thanks in advance for your time. I have a little problem with templates (I'm quite new in this templates thing).
The code is in C++ compiled (or at least tried to) with Visual studio 2012.
main.h:
class Main
{
public:
template<class T>
static void foo(T param1);
};
main.cpp
#include "main.h"
template<class T>
static void Main::foo(T param1)
{
// do things
}
other.h
#include "main.h"
class Other
{
public:
void foo2();
};
other.cpp
#include "other.h"
void Other::foo2()
{
int var1 = 10;
Main::foo(var1); // Here is the link error.
}
Well the problem as you probably know the quite common unresolved external symbol, so I've looked around the web in order to find something which can help me to understand and solve this link error and I've found a few things that I've already tried but without result.
I've tried:
1- Implement the foo function in the .h file
2- Use inline keyword
3- Tried with export (which actually is not supported by the compiler)
but none of those approachs seems to work with me, so obviously I'm doing something wrong or I'm missing something.
Remember that the templated function must be declared in "Main" class. Move the function to the "Other" class will not help me despite that can solve the error.
Error:
Error 5 error LNK2019: unresolved external symbol "public: static void __fastcall CGame::Push(char *,int,unsigned int &)" (??$Push@H@CGame@@SIXPADHAAI@Z) referenced in function "public: void __thiscall ClientManager::RequestLogin(int,char *)" (?RequestLogin@ClientManager@@QAEXHPAD@Z)
Where CGame would be Main, Push = foo(), ClientManager = Other and RequestLogin = foo2.
Thanks again for your time.