I have some trouble writing Resource class and ResourceManager template class
ResourceManager.h
[source lang="cpp"]#pragma once#include <unordered_map>#include <utility> //for std::pair#include "Resource.h"#include <string>template<class T> class ResourceManager{friend class Resource<T>;};template<>class ResourceManager<sf::Music>{private: std::unordered_map<std::string, std::pair<int, sf::Music>> resourceMap;public:};[/source]
Resource.h
[source lang="cpp"]#pragma once#include <SFML\Audio.hpp>#include "ResourceManager.h"template<class T> class Resource;template<> class Resource<sf::Music>{private: static ResourceManager<sf::Music> manager;//Cause of error};[/source]
Errors I get;
error C2143: syntax error : missing ';' before '<'
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2238: unexpected token(s) preceding ';'
2 replies to this topic
Sponsor:
#2 Members - Reputation: 615
Posted 08 November 2012 - 10:27 PM
I fixed the error and now must define a constructor
ResourceManager.h
[source lang="cpp"]#pragma once#include <unordered_map>#include <utility> //for std::pair#include <SFML/Audio.hpp>#include <string>template<class T> class Resource;template<class T> class ResourceManager{friend class Resource<T>;};template<>class ResourceManager<sf::Music>{private: std::unordered_map<std::string, std::pair<int, sf::Music>> resourceMap;public: ResourceManager();}; ResourceManager<sf::Music>::ResourceManager(){}[/source]
Resource.h
[source lang="cpp"]#pragma once#include <SFML\Audio.hpp>#include "ResourceManager.h"template<> class Resource<sf::Music>{private: static ResourceManager<sf::Music> manager;};[/source]
When I compile this, I get linker error
1>HomeMenuScene.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>main.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>PlayingScene.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>SettingMenuScene.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>C:\Users\Park\Documents\Visual Studio 2012\Projects\Game3\Debug\Game3.exe : fatal error LNK1169: one or more multiply defined symbols found
ResourceManager.h
[source lang="cpp"]#pragma once#include <unordered_map>#include <utility> //for std::pair#include <SFML/Audio.hpp>#include <string>template<class T> class Resource;template<class T> class ResourceManager{friend class Resource<T>;};template<>class ResourceManager<sf::Music>{private: std::unordered_map<std::string, std::pair<int, sf::Music>> resourceMap;public: ResourceManager();}; ResourceManager<sf::Music>::ResourceManager(){}[/source]
Resource.h
[source lang="cpp"]#pragma once#include <SFML\Audio.hpp>#include "ResourceManager.h"template<> class Resource<sf::Music>{private: static ResourceManager<sf::Music> manager;};[/source]
When I compile this, I get linker error
1>HomeMenuScene.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>main.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>PlayingScene.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>SettingMenuScene.obj : error LNK2005: "public: __thiscall ResourceManager<class sf::Music>::ResourceManager<class sf::Music>(void)" (??0?$ResourceManager@VMusic@sf@@@@QAE@XZ) already defined in LogicManager.obj
1>C:\Users\Park\Documents\Visual Studio 2012\Projects\Game3\Debug\Game3.exe : fatal error LNK1169: one or more multiply defined symbols found
Edited by lride, 08 November 2012 - 10:52 PM.
An invisible text.
#3 Members - Reputation: 683
Posted 09 November 2012 - 03:19 AM
Put the constructor to .cpp or inline it.
ResourceManager<sf::Music>::ResourceManager()
{
}
It should be in .cpp file as you specialized the template, or just add inline before the declaration.
ResourceManager<sf::Music>::ResourceManager()
{
}
It should be in .cpp file as you specialized the template, or just add inline before the declaration.
http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.






