如何用declspac(dllexport)导出一个类的static(静态)变量
我是这样写的:
.h:
class CStaticTest{
public:
static int nUser;
static int GetUser();
static void SetUser(int nNewUser);
};
extern "C" __declspec(dllexport) int GetU();
.cpp:
static int GetUser()
{
return CStaticTest::nUser;
}
static void SetUser(int nNewUser)
{
CStaticTest::nUser = nNewUser;
}
extern "C" __declspec(dllexport) int GetU()
{
int n = CStaticTest::GetUser();
return n;
}
编译无法通过,是GetU函数里调用了GetUser的缘故。
问题点数:20、回复次数:4Top
1 楼m_halfman(半人)回复于 2006-03-14 09:21:34 得分 0
没人知道吗?Top
2 楼goodboyws(深夜不眠者(VCMVP))回复于 2006-03-14 09:27:56 得分 5
GetUser定义不对
static int GetUser()
{
return CStaticTest::nUser;
}
改为
int CStaticTest::GetUser()
{
return CStaticTest::nUser;
}
Top
3 楼luokun(信誉分只跌不涨)回复于 2006-03-14 09:45:32 得分 15
如楼上所说,但你还得在cpp的前面加上
int CStaticTest::nPass;
int CStaticTest::nUser;
否则还是会报错的。Top
4 楼wfy1971()回复于 2006-05-26 18:10:08 得分 0
我通AFX_EXT_CLASS导出含有static成员的类时,在使用导出类时链接不上static成员
StdAfx.obj : error LNK2001: unresolved external symbol "protected: static int YfMenu::xp_draw_3D_bitmaps" (?xp_draw_3D_bitmaps@YfMenu@@1HA)Top




