class LifeCircleLogger{
string m_msg;
public:
LifeCircleLogger(){}
LifeCircleLogger(const string& msg):m_msg(msg){
CCLog("%s BEGINS!",m_msg.c_str());
}
~LifeCircleLogger(){CCLog("%s ENDS!",m_msg.c_str());}
};
#define LOG_FUNCTION_LIFE LifeCircleLogger(__FUNCTION__);
```
上面这个是我从书上看来的,但一运行就报以下错误
*--- Begin quote from ____*
1>------ 已启动生成: 项目: HelloWorld, 配置: Debug Win32 ------
1> LifeCircleLogger.cpp
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(2): error C2146: 语法错误: 缺少“;”(在标识符“m_msg”的前面)
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(2): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(5): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(5): error C2143: 语法错误 : 缺少“,”(在“&”的前面)
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(5): error C2065: “msg”: 未声明的标识符
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(5): error C2614: “LifeCircleLogger”: 非法的成员初始化:“m_msg”不是基或成员
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(6): error C2065: “m_msg”: 未声明的标识符
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(6): error C2228: “.c_str”的左边必须有类/结构/联合
1> 类型是“'unknown-type'”
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(6): error C3861: “CCLog”: 找不到标识符
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(8): error C2065: “m_msg”: 未声明的标识符
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(8): error C2228: “.c_str”的左边必须有类/结构/联合
1> 类型是“'unknown-type'”
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(8): error C3861: “CCLog”: 找不到标识符
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.cpp(3): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.cpp(5): error C2084: 函数“LifeCircleLogger::LifeCircleLogger(void)”已有主体
1> f:\cocos2d-x-2.2.1\projects\helloworld\proj.win32\lifecirclelogger.h(4) : 参见“{ctor}”的前一个定义
*--- End quote*
string类没找到
#include
using namespace std;
尝试一下这个方法,然后不行做一个demo发上来。在这贴链接
— Begin quote from ____
引用第1楼harris于2013-12-31 09:53发表的 :
string类没找到
#include
using namespace std; http://www.cocoachina.com/bbs/job.php?action=topost&tid=175984&pid=866331
— End quote