【发布时间】:2012-02-09 11:33:30
【问题描述】:
所以我决定将我的类(资源管理器类)更改为 C++ 中的静态类 我收到一条我无法理解的错误消息......也许你们可以帮助我? :)
头文件如下:
#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H
#include <iostream>
#include <map>
#include <string>
#include "Image.h"
namespace sz {
typedef std::map<std::string, sz::Image> TStrImageMap;
typedef std::pair<std::string, sz::Image> TStrImagePair;
class ResourceManager {
private:
static TStrImageMap images; // Name, Image(sz::Image)
public:
static void AddImage(std::string name, std::string path);
//void AddSound();
static sz::Image &GetImage(std::string name);
//GetSound();
};
}
#endif
这是我得到的错误:
1>------ Build started: Project: Basic SFML, Configuration: Debug Win32 ------
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>ResourceManager.obj : error LNK2001: unresolved external symbol "private: static class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class sz::Image,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class sz::Image> > > sz::ResourceManager::images" (?images@ResourceManager@sz@@0V?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VImage@sz@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@VImage@sz@@@std@@@2@@std@@A)
1>C:\Users\Gannash\Desktop\Game Project\Debug\Basic SFML.exe : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
请对我刚接触stackoverflow的人温柔一点:D
【问题讨论】:
-
在 C++ 中,您必须定义静态类成员以便分配它们;另见C++ FAQ on this topic。