【问题标题】:How to work with static variables in clases with the Android NDK?如何使用 Android NDK 处理类中的静态变量?
【发布时间】:2015-09-22 07:16:15
【问题描述】:

我只是想用 NDK 编译一个简单的类(适用于 GCC 编译):

ShaderProgramManager.h:

namespace Graphics {

class ShaderProgramManager {
public:
    ShaderProgramManager();
    virtual ~ShaderProgramManager();
    static Graphics::ZGLProgram* ColoredVertexProgram;
};

} /* namespace Graphics */

ShaderProgramManager.cpp:

#include "ShaderProgramManager.h"

namespace Graphics {

ShaderProgramManager::ShaderProgramManager() {
    ShaderProgramManager::ColoredVertexProgram=new ZGLProgram();
}

错误是:

undefined reference to 'Graphics::ShaderProgramManager::ColoredVertexProgram'

如果我将变量声明为非静态就没有问题。

【问题讨论】:

    标签: c++11 android-ndk static-variables


    【解决方案1】:

    好的。要正确定义静态变量,必须在编译单元和外部方法中重新声明它们。

    本例中正确的 ShaderProgramManager.cpp:

    #include "ShaderProgramManager.h"
    
    namespace Graphics {
    
    Graphics::ZGLProgram* ShaderProgramManager::ColoredVertexProgram;
    
    ShaderProgramManager::ShaderProgramManager() {
        ColoredVertexProgram=new ZGLProgram();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-25
      • 1970-01-01
      • 2019-10-20
      • 2010-09-22
      相关资源
      最近更新 更多