刚学模板,一个编译问题
//A.h
#ifndef _A
#define _A
template<bool b=false>
class A1
{
public:
A1();
void F();
};
#endif
//A.cpp
#include "A.h"
template<bool b>
A1<b>::A1()
{
}
template<bool b>
void A1<b>::F()
{
}
//main.cpp
//main函数中
A1<false> a;
a.F();
编译后提示错误:
Linking...
Testt.obj : error LNK2001: unresolved external symbol "public: void __thiscall A1<0>::F(void)" (?F@?$A1@$0A@@@QAEXXZ)
Testt.obj : error LNK2001: unresolved external symbol "public: __thiscall A1<0>::A1<0>(void)" (??0?$A1@$0A@@@QAE@XZ)
Debug/Testt.exe : fatal error LNK1120: 2 unresolved externals
那位老大给我解释一下,谢谢了