我有以下类实现必须使用单个全局数组的静态方法。它是这样定义的:
//Defined in LockTrack.h file
enum LOCK_ID{
LOCKID_0,
LOCKID_1,
LOCKID_2,
LOCKID_COUNT
};
static LOCK_ID __glob_lock_ids[LOCKID_COUNT];
class CLockTrack
{
public:
static void getLockedLocks(/*parameters*/)
{
//__glob_lock_ids = points to 0x015ef558 address in memory
LOCK_ID lockID = __glob_lock_ids[0];
}
static void inline setLock(LOCK_ID lockID)
{
//__glob_lock_ids = points to 0x015ef330 address in memory
__glob_lock_ids[lockID] = LOCK_ON_FLAG;
}
};
但是发生的情况是'__glob_lock_ids'指针指向每个方法中的不同内存位置。为什么?以及如何解决这个问题?