开发者

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

开发者 https://www.devze.com 2022-12-28 08:15 出处:网络
I have the following source code : // main.cpp #include \"a.h\" int main() { A::push(100); } // a.cpp #include \"a.h\"

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.


The problem solved by using

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

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

It seems that you need to provide more hint to VC6, compared with VC2008.

0

精彩评论

暂无评论...
验证码 换一张
取 消