C++ - LNK2001 error

C++ - LNK2001 error

本文关键字:error LNK2001 C++      更新时间:2023-10-16

我想尝试一下C++应用程序,但我总是收到LNK2001错误,我不知道我做错了什么。

有人可以帮我吗?

  #ifndef CONTENTMANAGER_H
    #define CONTENTMANAGER_H
    #include "SFMLGraphics.hpp"
    #include <map>
    #include <sstream>
    using namespace sf;
    using namespace std;

    static class CONTENTMANAGER
    {
    public:
            static Texture getTexture(string textureName)
            {
                    if(textureMap.find(textureName) == textureMap.end())
                    {
                                    Texture texture;
                                    stringstream ss;
                                    ss<<"Texture"<<textureName<<".png";
                                    texture.loadFromFile(ss.str());
                                    textureMap.emplace(textureName, texture);
                                    return textureMap[textureName];
                    }
                    else
                    {
                            return textureMap[textureName];
                    }
            }
    private:
            static map<string,Texture> textureMap;
    };


    #endif

错误消息:http://www.bilderhoster.net/safeforbilder/5mdt1tzc.png

这是一个简单的错误,错误混乱中有很多包袱!

您尚未定义名为"textureMap"的静态成员变量。您实际上在链接时收到未定义的符号错误。

在.cpp文件中,请定义该变量。这应该可以解决您的问题。