class Test
{
public:
Test(void);
virtual ~Test(void);
CString GetStaticA();
CString GetStaticB();
};
Test::Test(void)
{
}
Test::~Test(void)
{
}
CString Test::GetStaticA()
{
static CString myTTT;
myTTT = "123456";
return myTTT ;
}
CString Test::GetStaticB()
{
CString myTTT;
myTTT = "123456";
return myTTT ;
}
//Test 为全局对象
Test myTest;
//全局函数
__declspec(dllexport) char * testDllStaticA()
{
//这种情况下,返回值是一长串"哈哈哈哈"
return myTest.GetStaticA().GetBuffer(0);
}
__declspec(dllexport) char * WINAPI testDllStaticB()
{
static CString testB;
testB = myTest.GetStaticB();
//这种情况下,返回值是"123456"
return testB .GetBuffer(0);
}
C++ static CString 变量在成员函数与全局函数中的不同表现
最新推荐文章于 2018-10-23 15:50:00 发布