cocos2d-x using_ns_cc
cocos2d-x using_ns_cc
我需要知道Cocos2D-X在c++中的这句话的功能:
USING_NS_CC
代码示例:
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "GameOverScene.h"
USING_NS_CC;
HelloWorld::~HelloWorld()
{
if (_targets)
{
_targets->release();
_targets = NULL;
}
if (_projectiles)
{
_projectiles->release();
_projectiles = NULL;
}
// cpp don't need to call super dealloc
// virtual destructor will do this
}
根据cocos2d-x源代码宏相当于using namespace cocos2d
。
你可以在cocos2d-x仓库的CCPlatformMacros.h中自己检查:
#ifdef __cplusplus
#define NS_CC_BEGIN namespace cocos2d {
#define NS_CC_END }
#define USING_NS_CC using namespace cocos2d
#define NS_CC ::cocos2d
#else
#define NS_CC_BEGIN
#define NS_CC_END
#define USING_NS_CC
#define NS_CC
#endif
对于@rene的回答,我查看了作者Siddharth Shekar的"Learning Cocos2d-x Game Development",作者错了。
这是本书那一段的链接,这是该段的图片。
关于USING_NS_CC
他写错了什么:
它不"
#include CCPlatformMacros.h
",它不加载额外的宏要使用它,您需要通过添加直接包含
CCPlatformMacros.h
#include <cocos/CCPlatformMacros.h>
或间接地通过添加其他包含它的头,例如#include <cocos2d.h>
。它没有将命名空间设置为
cocos2d
它包含了来自
cocos2d
命名空间的所有符号,这使得你可以使用cocos2d-x符号而不指向正确的cocos2d::
。为你的符号设置一个命名空间
cocos2d
,你应该使用namespace cocos2d { // some declarations/definitions }
或相当于:
NS_CC_BEGIN // some declarations/definitions NS_CC_END
相关文章:
- 如何使用CMake编译.proto文件来生成.grpcp.pb.cc和.grpc.pb.h文件
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- 使用 sprintf 将十六进制0xAABBCC转换为字符串"AA:BB:CC"
- F 张量流/核心/common_runtime/device_factory.cc:77]具有相同优先级 210 的 G
- 为什么cc可以编译一个c++程序?
- 使用 g++ 编译时列出所有 cpp/cc 文件是否正常?
- gRPC trace.cc 的方法 TraceFlagList::Add(TraceFlag* flag) 使其链接列表
- 在 centOS7 上安装 ceres-solver 并让 helloworld.cc 工作
- InstallApplicatonEventHandler/NSNotificationCenter 不通知事件 (NS
- 在头文件和 .cc 文件之间建立关系
- 如何在NS-3中使用Ramdomwaypoint模型时设置位置分配器
- WebRTC 'goog-remb' 和 'transport-cc' SDP lines
- 是否有NS-3.29的任何人嵌入aqua-sim-ng
- 在 Ubuntu 16.04 下构建 Android linphone 给出了 CC 和 CXX 的 cmake 路径变
- 如何在makefile中添加.c,.cc和.so文件以创建另一个.so
- 在NS3中运行示例sixlowpan.cc
- cc.game.restart() carsh when extend sdkbox in cocos2d-js 3.1
- NS-3 VANET:如何实现简单的交叉点场景?
- 如何访问其他 .cc 文件中命名空间中定义的函数