23 long long
long long max = 123123123123;
sprintf(temp,"%lld",max);
long long my_atoll(char *instr)
{
long long retval;
int i;
retval = 0;
for (; *instr; instr++) {
retval = 10*retval + (*instr - '0');
}
return retval;
}
long long my_atoll(char *instr)
{
long long retval;
int i;
retval = 0;
for (; *instr; instr++) {
retval = 10*retval + (*instr - '0');
}
return retval;
}
22 函数指针
Function1 f1 = XXX; // (函数名)
typedef void (CCObject::*SEL_MenuHandler)(CCObject*); // 声明
SEL_MenuHandler sm = (SEL_MenuHandler)(&UILayer::onBeiBaoClicked);// 赋值
(m_pListener->*m_pfnSelector)(this); // 调用
参考 LINK
21 void参数
void CCDirector::popScene(void)
vsvoid CCDirector::popScene()
C++ 上面2种相等 都表示无参数http://www.cnblogs.com/thinkingfor/archive/2010/09/14/1825842.html
20 private继承
http://baike.baidu.com/view/4024151.htm
私有基类中的成员 在私有派生类中的访问属性
私有成员 不可访问
公用成员 私有
保护成员 私有
19 virtual
虚函数,纯虚函数
对象多态,函数的后期动态绑定,调用的时候才知道调用哪个方法
18 struct继承类
struct就是简单的类
17 C++式类型转换
http://www.cppblog.com/pjqblues/archive/2007/10/23/34945.html
http://dev.yesky.com/193/2568193.shtml
16 引用使用
http://blog.csdn.net/windy_net/article/details/6096812
15 byte 不是基本类型
用 char14.同等级操作符 先执行右边再左边
unsigned short bs_version = (pBuffer[offset++] & 0xff) + ((pBuffer[offset++] & 0xff) << 8); // 错误
保险起见写成下面这种:
unsigned short bs_version = (pBuffer[offset] & 0xff) + ((pBuffer[offset+1] & 0xff) << 8);
offset +=2;
13.不能用try-catch
try-catch is not supported on android NDK
12 输出log
CCLog CCLOG
11. int to char* string
char buf[10]; sprintf(buf,"%d",100); string b= buf;
string char* to int
string str= "12345 ";
int b = atoi(str.c_str());
10.c_str()
9. printf sprintf fprintf
8.void(0)
== /* Nothing to do */
相当于空语句
7.string转 CCRect CCPoint CCSize
#include "CCNS.h"
6.断言
char msg[256] = {0};
sprintf(msg, "文件读取出错: %s", pszFilename);
CCAssert(!pBuffer, msg);
#define CCAssert(cond, msg) CC_ASSERT(cond)
改成:
#define CCAssert(cond, msg) CC_ASSERT(msg && cond)
http://blog.sina.com.cn/s/blog_61d2d3f50100zgz8.html
有问题 msg显示不出来
5.文件读取
// 全路径
const char *fullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(pszFilename);
// 读取文件
unsigned long nSize = 0;
unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullPath, "rb", &nSize);
4.会调用retain的操作
CCDictionary添加对象
CCArray添加对象
CCNode
CCSet
CCAction
3.static变量的声明
直接放在cpp里声明?,作用域只在本文件,一般当成单例用。
static CCSpriteFrameCache *pSharedSpriteFrameCache = NULL;
.h文件里,作用域只在本类
private
static CCSpriteFrameCache *pSharedSpriteFrameCache
2.private public protected static 限定符只需要在.h文件里标示,cpp里不需要
但返回值值和域名需要。
1.VS快速格式化代码(只能小范围使用)
选中 - 左键点选中的区域