cocos2d-x 静态变量 static

在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::A(void)
{
}
A::~A(void)
{    
}
int A::getInt()
{    
    return staticInt ;
}
原文地址:https://www.cnblogs.com/C-Plus-Plus/p/4053665.html