c++ - How to call a static template member function from another class -


first of in advance time. have little problem templates (i'm quite new in templates thing).

the code in c++ compiled (or @ least tried to) 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) {   // 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 link error. } 

well problem know quite common unresolved external symbol, i've looked around web in order find can me understand , solve link error , i've found few things i've tried without result.

i've tried:

1- implement foo function in .h file

2- use inline keyword

3- tried export (which not supported compiler)

but none of approachs seems work me, i'm doing wrong or i'm missing something.

remember templated function must declared in "main" class. move function "other" class not me despite can solve 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 main, push = foo(), clientmanager = other , requestlogin = foo2.

thanks again time.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -