簡體   English   中英

Static function 無法訪問或使用 C++

[英]Static function can not be accessed or used C++

我正在嘗試使用 static class,但由於某種原因,我遇到了一個非常無用的錯誤。

這是我正在嘗試訪問的 static class:

static class Camera
{

public:
    Camera();
    ~Camera();

    static glm::mat4 viewMatrix;

    static void move(float x, float y, float z) {// add 3 more values for the cube
        viewMatrix = glm::lookAt(glm::vec3(x, y, z),glm::vec3(0.0f, 0.0f, 0.0f),glm::vec3(0.0f, 1.0f, 0.0f));
    } 


    static glm::mat4 getViewMatrix() {
        return viewMatrix;
    }
};

這是我試圖訪問 function 的方式:

 Camera::move(xdist, ydist, zdist);

錯誤:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol "public: static struct glm::detail::tmat4x4<float> Camera::viewMatrix" (?viewMatrix@Camera@@2U?$tmat4x4@M@detail@glm@@A) sample  

已解決,將其添加到 cpp 文件中:

 glm::mat4 Camera::viewMatrix = glm::mat4(1.0);

需要在.cpp而不是.h文件中初始化viewMatrix

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM