Having template function defination in cpp file - Not work for VC6

Posted by Yan Cheng CHEOK on Stack Overflow See other posts from Stack Overflow or by Yan Cheng CHEOK
Published on 2010-04-29T02:20:15Z Indexed on 2010/04/29 2:27 UTC
Read the original article Hit count: 468

Filed under:
|

I have the following source code :

// main.cpp
#include "a.h"

int main() {
    A::push(100);
}

// a.cpp
#include "a.h"

template <class T>
void A::push(T t) {
}

template void A::push(int t);    

// a.h
#ifndef A_H
class A {
public:
    template <class T>
    static void push(T t);
};
#endif

The code compiled charming and no problem under VC2008.

But when come to my beloved VC6, it give me error :

main.obj : error LNK2001: unresolved external symbol "public: static void __cdecl A::push(int)" (?push@A@@SAXH@Z)

Any workaround? I just want to ensure my function definition is re-inside cpp file.

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++