各位:为什么类的静态成员函数的实现必须放在.h文件中?
//t.h
class Ctest
{
public:
Ctest();
static int GetM();
static int m_int ;
};
//t.cpp
#include "t.h"
int Ctest::GetM()
{
return m_int;
}
Ctest()::Ctest():m_int(1){};
// test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "t.h"
#include "iostream.h"
int _tmain(int argc, _TCHAR* argv[])
{
cout<<Ctest::GetM()<<endl;
return 0;
}
//编译的提示
test error LNK2019: 无法解析的外部符号 "public: static int __cdecl Ctest::GetM(void)" (?GetM@Ctest@@SAHXZ) ,该符号在函数 _main 中被引用