C++问题记录

23 long long

long long to str
long long max = 123123123123;
sprintf(temp,"%lld",max);

str to longlong

 long long my_atoll(char *instr)
{
  long long retval;
  int i;
  retval = 0;
  for (; *instr; instr++) {
    retval = 10*retval + (*instr - '0');
  }
  return retval;
}

22 函数指针

指向函数的 指针

C模式:
typedef void (*Function1)( ); //定义一个函数指针类型。
Function1 f1 = XXX; // (函数名)

C++模式:

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)

vs

void CCDirector::popScene()

C++ 上面2种相等 都表示无参数
C f() 表示的是不确定参数个数

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 不是基本类型

用 char

14.同等级操作符 先执行右边再左边

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

C++中对sprintf()函数的说明(转)


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快速格式化代码(只能小范围使用)

选中 - 左键点选中的区域


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值