码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d-x 静态变量 static

时间:2014-10-27 12:15:56      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   sp   文件   div   log   bs   

在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

标签:style   blog   color   os   sp   文件   div   log   bs   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!