代码如下:

HelloWorldScene.h

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
class HelloWorld : public cocos2d::Layer
{
public:
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();

// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();

// a selector callback
    void menuCloseCallback(cocos2d::Ref* pSender);
    void addMonster(float dt);
    void GameUpdate(float);
    // implement the "static create()" method manually
    virtual bool onTouchBegan(Touch* pTouch, Event* pEvent);
    virtual void onTouchMoved(Touch* pTouch, Event* pEvent);
    virtual void onTouchEnded(Touch* pTouch, Event* pEvent);

bool onContactBegin(const PhysicsContact& contact);

CREATE_FUNC(HelloWorld);
private:
    std::vector<cocos2d::Sprite*> Monster;
    std::vector<cocos2d::Sprite*> projectile;
    EventListenerTouchOneByOne* touch_listener;
    EventListenerPhysicsContact* contact_listener;
    Sprite* _player;
    int i, j;
};

#endif // __HELLOWORLD_SCENE_H__

报错:

Error    4    error C2061: syntax error : identifier 'Touch' (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    19    1    hello
Error    6    error C2061: syntax error : identifier 'Touch' (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    20    1    hello
Error    8    error C2061: syntax error : identifier 'Touch' (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    21    1    hello
Error    3    error C2061: syntax error : identifier 'Touch' (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    19    1    hello
Error    5    error C2061: syntax error : identifier 'Touch' (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    20    1    hello
Error    7    error C2061: syntax error : identifier 'Touch' (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    21    1    hello
Error    37    error C2065: '_player' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    84    1    hello
Error    38    error C2065: '_player' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    85    1    hello
Error    40    error C2065: '_player' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    86    1    hello
Error    53    error C2065: '_player' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    166    1    hello
Error    56    error C2065: '_player' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    168    1    hello
Error    59    error C2065: '_player' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    169    1    hello
Error    25    error C2065: 'touch_listener' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    45    1    hello
Error    26    error C2065: 'touch_listener' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    46    1    hello
Error    28    error C2065: 'touch_listener' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    47    1    hello
Error    30    error C2065: 'touch_listener' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    48    1    hello
Error    32    error C2065: 'touch_listener' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    49    1    hello
Error    34    error C2065: 'touch_listener' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    50    1    hello
Error    36    error C2065: 'touch_listener' : undeclared identifier    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    51    1    hello
Error    12    error C2143: syntax error : missing ',' before '&' (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    23    1    hello
Error    11    error C2143: syntax error : missing ',' before '&' (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    23    1    hello
Error    14    error C2143: syntax error : missing ';' before '*' (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    30    1    hello
Error    18    error C2143: syntax error : missing ';' before '*' (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    31    1    hello
Error    22    error C2143: syntax error : missing ';' before '*' (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    32    1    hello
Error    13    error C2143: syntax error : missing ';' before '*' (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    30    1    hello
Error    17    error C2143: syntax error : missing ';' before '*' (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    31    1    hello
Error    21    error C2143: syntax error : missing ';' before '*' (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    32    1    hello
Error    50    error C2227: left of '->addChild' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    165    1    hello
Error    57    error C2227: left of '->getContentSize' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    168    1    hello
Error    54    error C2227: left of '->getPosition' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    166    1    hello
Error    60    error C2227: left of '->getPosition' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    169    1    hello
Error    29    error C2227: left of '->onTouchBegan' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    47    1    hello
Error    35    error C2227: left of '->onTouchCancelled' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    50    1    hello
Error    33    error C2227: left of '->onTouchEnded' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    49    1    hello
Error    31    error C2227: left of '->onTouchMoved' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    48    1    hello
Error    43    error C2227: left of '->removeChild' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    138    1    hello
Error    45    error C2227: left of '->removeChild' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    139    1    hello
Error    63    error C2227: left of '->runAction' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    173    1    hello
Error    39    error C2227: left of '->setPosition' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    85    1    hello
Error    27    error C2227: left of '->setSwallowTouches' must point to class/struct/union/generic type    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    46    1    hello
Error    51    error C2228: left of '.back' must have class/struct/union    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    165    1    hello
Error    62    error C2228: left of '.back' must have class/struct/union    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    173    1    hello
Error    48    error C2228: left of '.push_back' must have class/struct/union    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    164    1    hello
Error    58    error C2228: left of '.width' must have class/struct/union    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    168    1    hello
Error    61    error C2228: left of '.y' must have class/struct/union    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    169    1    hello
Error    41    error C2511: 'bool HelloWorld::onContactBegin(const cocos2d::PhysicsContact &)' : overloaded member function not found in 'HelloWorld'    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    134    1    hello
Error    46    error C2511: 'bool HelloWorld::onTouchBegan(cocos2d::Touch *,cocos2d::Event *)' : overloaded member function not found in 'HelloWorld'    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    151    1    hello
Error    65    error C2511: 'void HelloWorld::onTouchEnded(cocos2d::Touch *,cocos2d::Event *)' : overloaded member function not found in 'HelloWorld'    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    183    1    hello
Error    64    error C2511: 'void HelloWorld::onTouchMoved(cocos2d::Touch *,cocos2d::Event *)' : overloaded member function not found in 'HelloWorld'    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    178    1    hello
Error    47    error C2597: illegal reference to non-static member 'HelloWorld::j'    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    157    1    hello
Error    52    error C2597: illegal reference to non-static member 'HelloWorld::j'    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    165    1    hello
Error    55    error C2660: 'cocos2d::ccpSub' : function does not take 1 arguments    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    166    1    hello
Error    42    error C2671: 'HelloWorld::onContactBegin' : static member functions do not have 'this' pointers    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    138    1    hello
Error    44    error C2671: 'HelloWorld::onContactBegin' : static member functions do not have 'this' pointers    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    139    1    hello
Error    49    error C2671: 'HelloWorld::onTouchBegan' : static member functions do not have 'this' pointers    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    165    1    hello
Error    10    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    23    1    hello
Error    16    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    30    1    hello
Error    20    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    31    1    hello
Error    24    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    32    1    hello
Error    9    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    23    1    hello
Error    15    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    30    1    hello
Error    19    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    31    1    hello
Error    23    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\classes\helloworldscene.h    32    1    hello
Warning    66    warning C4018: '<' : signed/unsigned mismatch    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    190    1    hello
Warning    67    warning C4018: '<' : signed/unsigned mismatch    e:\cocos2d-x\samples\hello\classes\helloworldscene.cpp    192    1    hello
Warning    2    warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss (..\Classes\AppDelegate.cpp)    e:\cocos2d-x\samples\hello\cocos2d\cocos\physics\ccphysicsjoint.h    1    1    hello
Warning    1    warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss (..\Classes\HelloWorldScene.cpp)    e:\cocos2d-x\samples\hello\cocos2d\cocos\physics\ccphysicsjoint.h    1    1    hello

解决方法:

在行#include "cocos2d.h"下增加如下代码行:
USING_NS_CC;

cocos2d-x 头文件中添加方法变量导致编译报错的更多相关文章

  1. VS2010在C#头文件中添加文件注释的方法

    步骤: 1.VS2010 中找到安装盘符(本人安装目录在D盘,所以以D盘为例)D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\I ...

  2. VS2010在C#头文件中添加文件注释的方法(转)

    步骤: 1.VS2010 中找到(安装盘符以D盘为例)D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTempl ...

  3. Qt - 错误总结 - 在自定义类头文件中添加Q_OBJECT 编译时报错(undefined reference to ‘vtable for xxThread)

    错误提示:在添加的QThread子类头文件添加Q_OBJECT时,编译程序,出现"undefined reference to 'vtable for xxThread'"错误提示 ...

  4. Loadrunner在场景中添加多个负载机报错:Action.c(38): Error -26488: Could not obtain information about submitted解决方法

    Error -26488: Could not obtain information about submitted file "E:\.jpg": _stat32 rc=-1, ...

  5. maven 项目 pom.xml文件中配置的jar包下载报错

    [ERROR] [ERROR] Some problems were encountered while processing the POMs:[ERROR] 'dependencies.depen ...

  6. 解决Mapper.xml文件中sql标签第一个字段报错

    在文件标头的http后边补上www 下边代码仅第4行有变动 原文件: <?xml version="1.0" encoding="UTF-8"?> ...

  7. Java中float浮点型变量不加F报错情况

    1 public class Text { 2 3 public static void main(String args[] ){ 4 float x=123.45; 5 System.out.pr ...

  8. [C/C++]在头文件中使用static定义变量意味着什么

    文章出处:http://www.cnblogs.com/zplutor/ 看到有一位同学在头文件中这么写: static const wchar_t* g_str1 = - static const ...

  9. 【原创】大叔问题定位分享(20)hdfs文件create写入正常,append写入报错

    最近在hdfs写文件的时候发现一个问题,create写入正常,append写入报错,每次都能重现,代码示例如下: FileSystem fs = FileSystem.get(conf); Outpu ...

随机推荐

  1. 跟Google学习Android开发-起始篇-用碎片构建一个动态的用户界面(3)

    4.3 构建一个灵活的用户界面 当设计你的应用程序要支持大范围的屏幕尺寸时,你可以在不同的布局配置中重用碎片,来根据可用的屏幕空间优化用户体验. 例如,在手持设备上,它可能是适应来在一个单窗格用户界面 ...

  2. uva 10555 - Dead Fraction)(数论)

    option=com_onlinejudge&Itemid=8&category=516&page=show_problem&problem=1496" st ...

  3. android 程序防止被360或者系统给kill掉

    关于如果和防止android 程序防止被360kill掉之后重启的问题,肯定大家也搜索了好多方法,都不好使,对不对,什么增高权限了,什么进程优先级了,这些东西都不是我们可控的,所以有没有一些非常保险的 ...

  4. 使用 Spring 2.5 基于注解驱动的 Spring MVC--转

    概述 继 Spring 2.0 对 Spring MVC 进行重大升级后,Spring 2.5 又为 Spring MVC 引入了注解驱动功能.现在你无须让 Controller 继承任何接口,无需在 ...

  5. Android(java)学习笔记259:JNI之NDK开发步骤

    1. NDK开发步骤(回忆一下HelloWorld案例): (1)创建工程 (2)定义native方法 (3)创建jni文件夹 (4)创建c源文件放到jni文件夹 (5)拷贝jni.h头文件到jni目 ...

  6. 关于安装PHP补装PDO与PDO_MYSQL操作

    我这里是通过PHP源码包来安装的 1.安装pdo cd到你的PHP源码包下的ext/pdo目录,然后执行如下操作: #/usr/local/php/bin/phpize   (/usr/local/p ...

  7. TCP Linger的坑

    昨天和同事奋战几个小时,解决了一个linger造成的bug. 现象是这样的,这是一个我从原型接手,扩充了各种功能成为可用代码的epoll实现的非阻塞socket server程序,接收大量的短连接,测 ...

  8. 监听视图树 OnGlobalLayoutListener

    背景 我们都知道在onCreate()里面获取控件的高度是0,这是为什么呢?我们来看一下示例: 首先我们写一个控件 public class MyImageView extends ImageView ...

  9. spring-data-mongodb一个系统xml文件里面配置两个数据源

    spring-data-mongodb一个系统xml文件里面配置两个数据源 参考文档如下: http://www.iteye.com/problems/92789 http://stackoverfl ...

  10. (转)SQL流程控制语句学习(一):变量及控制语句种类

    1.局部变量 用户自己定义的,称局部变量,以@标识. 作用范围:定义局部变量的批处理.存储过程.触发器和语句块 局部变量的定义: declare @局部变量名 数据类型 注意:变量的类型不能是text ...