Ich hab mal wieder ein kleines Problem. Ich wollte einen Resourcenmanager für Bilder und Fonts und so weiter für SFML schreiben.
Hierbei ist folgendes rausgekommen:
ResourceManager.hpp
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
#ifndef RESOURCEMANAGER_HPP
#define RESOURCEMANAGER_HPP
#include <string>
#include <map>
template<class ObjectType, class IdentifierType = std::string>
class CResourceManager
{
protected:
typedef ObjectType OT;
typedef IdentifierType IT;
std::map<IT, OT> _Resources;
class _DataNotFound{};
public:
CResourceManager(){}
virtual void loadResource(IT p_ResourceIdentifier) = 0;
OT* getResource(IT p_ResourceIdentifier);
virtual ~CResourceManager(){}
};
#endif
|
ResourceManager.cpp:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
|
#include "ResourceManager.hpp"
#include <algorithm>
template<class ObjectType, class IdentifierType> ObjectType* CResourceManager<ObjectType, IdentifierType>::getResource(IdentifierType p_ResourceIdentifier)
{
std::map<IT, OT>::iterator i;
i = find(_Resources.begin(), _Resources.end(), p_ResourceIdentifier);
if (i==_Resources.end()) throw _DataNotFound();
return &(i->second);
}
|
ImageManager.hpp:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#ifndef IMAGEMANAGER_HPP
#define IMAGEMANAGER_HPP
#include "ResourceManager.hpp"
#include <SFML/Graphics.hpp>
class CImageManager : public CResourceManager<sf::Image>
{
private:
class _BadImage{};
public:
void loadResource(std::string p_ResourceName);
};
#endif
|
ImageManager.cpp:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include "ImageManager.hpp"
void CImageManager::loadResource(std::string p_ResourceName)
{
sf::Image Image;
if(!Image.LoadFromFile(p_ResourceName))
{
throw _BadImage();
}
_Resources[p_ResourceName] = Image;
}
|
Folgenden Linkerfehler bekomme ich nun:
|
C-/C++-Quelltext
|
1
|
Game.obj : error LNK2019: Verweis auf nicht aufgelöstes externes Symbol ""public: class sf::Image * __thiscall CResourceManager<class sf::Image,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >::getResource(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getResource@?$CResourceManager@VImage@sf@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@@QAEPAVImage@sf@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)" in Funktion ""public: class sf::Image * __thiscall CFramework::getImage(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?getImage@CFramework@@QAEPAVImage@sf@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)".
|
Ich würde mich sehr über Hilfe freuen da ich mit Linker Fehlern dieser Art überhaupt keine Erfahrung habe.