未解析的外部符号“private: static float ObjectInfo::Rotation

unresolved external symbol "private: static float ObjectInfo::Rotation

    #include <iostream>

class ObjectInfo{
private:
    static float Rotation;
public:
    //sets object rotation value
    void SetR(float a){ static float Rotation = a; }
    //print roation value (I think this is where the problem is located)
    void PrintR(){ std::cout << Rotation;}
};

int main()
{
    ObjectInfo Wall;
    //set float var
    float Rotation;
    //Get user set rotation
    std::cin >> Rotation;
    //set wall rotation
    Wall.SetR(Rotation);
    //print wall rotation value
    Wall.PrintR();
    std::cin >> Rotation;
}

错误 1 ​​error LNK2001: 未解析的外部符号“private: static float ObjectInfo::Rotation” (?Rotation@ObjectInfo@@0MA)

错误 2 error LNK1120: 1 未解决的外部问题

This is a protype i made and i have no clue how to resolve the error.

Does anynyone know what could cause this error?

I get the same error if i try returning the value and then couting that value.

Does anyone know an alteriate solution to retreaving the value from the class?

您需要为您的静态成员分配存储空间,需要

float ObjectInfo::Rotation;

在您的 class 定义之外。