C++ 类静态成员的命名空间问题

宏定义如下:

#define NS_CC_EXT_BEGIN                     namespace cocos2d { namespace extension {
#define NS_CC_EXT_END                       }}

头文件如下:

#pragma once
#include <pthread\pthread.h>
#include "cocoa\CCArray.h"
#include "ExtensionMacros.h"

NS_CC_EXT_BEGIN

class NetworkCommunication
{

private:
	static NetworkCommunication * s_instance;

	static CCArray * s_requestQueue;
	static CCArray * s_responseQueue;

	static pthread_t s_networkReadThread;
	static pthread_t s_networkWriteThread;

	static pthread_mutex_t s_requestQueueMutex;
	static pthread_mutex_t s_responseQueueMutex;

	static pthread_mutex_t s_readThreadSleepMutex;
	static pthread_cond_t s_readThreadSleepCondition;

	static pthread_mutex_t s_writeThreadSleepMutex;
	static pthread_cond_t s_writeThreadSleepCondition;

public:
	static NetworkCommunication * getInstance();
	void start();
private:
	NetworkCommunication(void);
	~NetworkCommunication(void);
};

NS_CC_EXT_END

cpp文件内容如下:

#include "NetworkCommunication.h"

#include <pthread\pthread.h>

NS_CC_EXT_BEGIN



static void* networkReadThreadWork(void *data) {

	CCLog("Jonathan: in networkReadThreadWork");

	while (true) {

	}

	return NULL;
}

static void* networkWriteThreadWork(void *data) {
	CCLog("Jonathan: in networkWriteThreadWork");
	return NULL;
}

NetworkCommunication::NetworkCommunication(void)
{
	s_requestQueue = new CCArray();
	s_requestQueue->init();

	s_responseQueue = new CCArray();
	s_responseQueue->init();

	pthread_mutex_init(&s_requestQueueMutex, NULL);
	pthread_mutex_init(&s_responseQueueMutex, NULL);

	pthread_mutex_init(&s_readThreadSleepMutex, NULL);
	pthread_cond_init(&s_readThreadSleepCondition, NULL);

	pthread_mutex_init(&s_writeThreadSleepMutex, NULL);
	pthread_cond_init(&s_writeThreadSleepCondition, NULL);

	pthread_create(&s_networkReadThread, NULL, networkReadThreadWork, NULL);
	pthread_detach(s_networkReadThread);

	pthread_create(&s_networkWriteThread, NULL, networkWriteThreadWork, NULL);
	pthread_detach(s_networkWriteThread);
}


NetworkCommunication::~NetworkCommunication(void)
{
}

NetworkCommunication * NetworkCommunication::getInstance() {
	if (s_instance == NULL) {
		s_instance = new NetworkCommunication();
	}

	return s_instance;
}


NS_CC_EXT_END

按F7构建时,发生如下的错误:

3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static class cocos2d::extension::NetworkCommunication * cocos2d::extension::NetworkCommunication::s_instance" (?s_instance@NetworkCommunication@extension@cocos2d@@0PAV123@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static class cocos2d::CCArray * cocos2d::extension::NetworkCommunication::s_requestQueue" (?s_requestQueue@NetworkCommunication@extension@cocos2d@@0PAVCCArray@3@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static class cocos2d::CCArray * cocos2d::extension::NetworkCommunication::s_responseQueue" (?s_responseQueue@NetworkCommunication@extension@cocos2d@@0PAVCCArray@3@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct ptw32_handle_t cocos2d::extension::NetworkCommunication::s_networkReadThread" (?s_networkReadThread@NetworkCommunication@extension@cocos2d@@0Uptw32_handle_t@@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct ptw32_handle_t cocos2d::extension::NetworkCommunication::s_networkWriteThread" (?s_networkWriteThread@NetworkCommunication@extension@cocos2d@@0Uptw32_handle_t@@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct pthread_mutex_t_ * cocos2d::extension::NetworkCommunication::s_requestQueueMutex" (?s_requestQueueMutex@NetworkCommunication@extension@cocos2d@@0PAUpthread_mutex_t_@@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct pthread_mutex_t_ * cocos2d::extension::NetworkCommunication::s_responseQueueMutex" (?s_responseQueueMutex@NetworkCommunication@extension@cocos2d@@0PAUpthread_mutex_t_@@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct pthread_mutex_t_ * cocos2d::extension::NetworkCommunication::s_readThreadSleepMutex" (?s_readThreadSleepMutex@NetworkCommunication@extension@cocos2d@@0PAUpthread_mutex_t_@@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct pthread_cond_t_ * cocos2d::extension::NetworkCommunication::s_readThreadSleepCondition" (?s_readThreadSleepCondition@NetworkCommunication@extension@cocos2d@@0PAUpthread_cond_t_@@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct pthread_mutex_t_ * cocos2d::extension::NetworkCommunication::s_writeThreadSleepMutex" (?s_writeThreadSleepMutex@NetworkCommunication@extension@cocos2d@@0PAUpthread_mutex_t_@@A)
3>NetworkCommunication.obj : error LNK2001: 无法解析的外部符号 "private: static struct pthread_cond_t_ * cocos2d::extension::NetworkCommunication::s_writeThreadSleepCondition" (?s_writeThreadSleepCondition@NetworkCommunication@extension@cocos2d@@0PAUpthread_cond_t_@@A)
3>E:\cocos2d-x-2.2.3\projects\Example\proj.win32\Debug.win32\Example.exe : fatal error LNK1120: 11 个无法解析的外部命令


类的命名空间指定了之后,类静态成员的命名空间需要单独说明吗?先在这里mark一下这个问题,等后面有时间再研究这个问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值