代码如下:

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. OpenStack Networking

    今天的数据中心网络比以往不论什么时候包括的设备都要多,比如server.网络设备.存储系统和安全设备等.这当中有非常多被近一步划分为多个虚拟机和虚拟网络.IP地址的数量.路由配置和安全规则能够迅速达到 ...

  2. 不相交集python实现

    1.不相交集是解决等价关系的一种数据结构,执行合并和查找的速度都很快,M次执行合并和查找的执行时间为(M*logN). 在一个集合中.对于每一对元素(a,b),a,b∈S,对于关系R假设满足以下三个条 ...

  3. android的task任务栈

    转自http://blog.csdn.net/liuhe688/article/details/6761337 古人學問無遺力,少壯工夫老始成.紙上得來終覺淺,絕知此事要躬行.南宋.陸遊<冬夜讀 ...

  4. C# 在右下角弹出窗口

    窗口代码如下: using System; using System.Collections.Generic; using System.ComponentModel; using System.Da ...

  5. 使用HighCharts实现实时数据展示

    在众多的工业控制系统领域常常会实时采集现场的温度.压力.扭矩等数据,这些数据对于监控人员进行现场态势感知.进行未来趋势预测具有重大指导价值.工程控制人员如果只是阅读海量的数据报表,对于现场整个态势的掌 ...

  6. css中同时用头部引入和外部引入对同一个标签进行样式设置,哪一个优先级高。

    这段是html中的代码 <!doctype html> <html lang="en"> <head> <meta charset=&qu ...

  7. python 下的数据结构与算法---8:哈希一下【dict与set的实现】

    少年,不知道你好记不记得第三篇文章讲python内建数据结构的方法及其时间复杂度时里面关于dict与set的时间复杂度[为何访问元素为O(1)]原理我说后面讲吗?其实就是这篇文章讲啦. 目录: 一:H ...

  8. js动态新增组合Input标签

    var x = 1; function addlink() { var linkdiv = document.getElementById("add1_0"); if (linkd ...

  9. Installing node-oracledb on Microsoft Windows

    版本 7 由 Laura Ramsey-Oracle 于 2015-10-19 下午11:46创建,最后由 cj 于 2015-10-22 下午7:44修改. Installing node-orac ...

  10. Cookies欺骗分析与防护

    今天来谈谈cookies欺骗是怎么回事以及如何避免. 用户在登录之后通常会保存用户信息,以便在其他需要权限的页面去验证用户信息是否具有访问权限. 有同学说我在登录的时候已经很注意SQL注入问题了,还有 ...