代码如下:

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. java实现excel的导入导出(poi详解)

    经过两天的研究,现在对excel导出有点心得了.我们使用的excel导出的jar包是poi这个阿帕奇公司的一个项目,后来被扩充了.是比较好用的excel导出工具. 下面来认识一下这个它吧. 我们知道要 ...

  2. mysql中如何更新一个字段的值为它本身的值连接上一个字符串

    CONCAT(str1,str2,...)     返回结果为连接参数产生的字符串. 如有任何一个参数为NULL ,则返回值为 NULL. 或许有一个或多个参数. 如果所有参数均为非二进制字符串,则结 ...

  3. Max retries exceeded with ur

    requests模块在抓取网页时抛出ConnectionError异常,Max retries exceeded with url 主要搜下 "Caused by <class 'so ...

  4. angular指令浅谈

    今天在闲暇时间再次对angularjs的指令进行了初探,不探不知道一探吓一跳啊, 就一个简单的指令整整难住我了两个小时,先不说代码的逻辑是否复杂,就一些内部的一些实现让我看起来都是头疼的不行啊,不过最 ...

  5. 在MacOs上配置Hadoop和Spark环境

    在MacOs上配置hadoop和spark环境 Setting up Hadoop with Spark on MacOs Instructions 准备环境 如果没有brew,先google怎样安装 ...

  6. 95秀-PullToRefreshListView 示例

        正在加载.暂无数据页面 public class RefreshGuideTool {     private RelativeLayout rl_loading_guide;//整个View ...

  7. linux学习笔记<命令介绍>

    主要介绍日常工作中一些常用的命令,内容均整理自慕课网 命令提示符 [root@hgs ~]# 其中: root : 当前登录用户 hgs : 主机名 ~ : 当前所在目录(家目录),对于root用户, ...

  8. MSSQL 字符串替换语句

    MSSQL替换语句:update 表名 set 字段名=replace(cast(字段名 as varchar(8000)),'abc.com','123.com')例如:update PE_Arti ...

  9. sql语法图

  10. Java中的List(转)

    List包括List接口以及List接口的所有实现类.因为List接口实现了Collection接口,所以List接口拥有Collection接口提供的所有常用方法,又因为List是列表类型,所以Li ...