首页 > 其他 > 详细

cocos2d-x 静态变量 static

时间:2014-10-27 12:14:38      阅读:508      评论:0      收藏:0      [点我收藏+]

在cocos2d-x的.h文件里声明静态(static)变量时,编译运行的时候会出现“无法解析”的错误,这是因为我们错误的引用C++习惯,将静态(static)变量声明在头文件中导致的错误。

 

#ifndef _A_H_
#define _A_H_

#include "cocos2d.h"

class A{
public:
    static int getInt(); //获取创建的静态(static)变量
protected:
        A();
    ~A();
};

#endif
#include "A.h"

using namespace cocos2d;

static int staticInt = 0; //要把静态变量声明定义在这里才行

A(void)
{
}
A::~A(void)
{    
}
int A::getInt()
{    
    return staticInt ;
}

 

cocos2d-x 静态变量 static

原文:http://www.cnblogs.com/C-Plus-Plus/p/4053665.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!