Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Resource Manager  (Read 3184 times)

0 Members and 1 Guest are viewing this topic.

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Resource Manager
« on: July 25, 2012, 05:23:46 pm »
I'm trying to create a resource manager, here's my main abstract class for the other managers to inherit from. I'm trying to use a templated class so it can be generic:

Manager.h:

namespace ShockEngine {
    template<class T> class Manager {
    protected:
        std::map<std::string, T> mediaList;
       
    public:
        virtual T getMedia(const T& fileName) = 0;
    };
}

Here's my texture manager, which is a derived class of Manager:

TextureManager.h:

#include "Manager.h"

namespace ShockEngine {
    class TextureManager: public Manager<sf::Texture> {
    protected:
        std::map<std::string, sf::Texture> textureList;
       
    public:
        TextureManager();
        virtual ~TextureManager();
       
        Manager<sf::Texture> addMedia(const std::string& fileName);
    };
   
    static TextureManager textureManager;
}

When I try to build and run this, 3 errors come up with my static definition of a texturemanager object, saying "Variable type TextureManager is an abstract class" I've tried to rewrite the template, use different techniques, but nothing works.
Current Projects:
Technoport

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Resource Manager
« Reply #1 on: July 25, 2012, 05:52:22 pm »
Then don't declare the destructor of your TextureManager as virtual and implement the getMedia function from the Manager class. ;)
Also read somethings about the virtual keyword and abstract classes. If you don't understand why this error appears then you're lacking major knowledge there. ;)
« Last Edit: July 26, 2012, 12:31:44 am by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: Resource Manager
« Reply #2 on: July 25, 2012, 11:46:34 pm »
TheTerminator, it looks like you need to learn about when to use which abstraction mechanism. Why do you use templates? There is no generic code, you still write a specific std::map in the texture class.

And why do you use inheritance (or even more, polymorphism)? When will you ever work with an abstract base pointer Manager<sf::Texture>* if you refer to TextureManager?

Additionally, protected member variables and static variables in the global namespace (especially in header files) are questionable because of encapsulation and linkage, respectively.

Deconstructor
The function is called destructor ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Resource Manager
« Reply #3 on: July 26, 2012, 12:38:12 am »
The function is called destructor ;)
Man, I always write that wrong... ::) :-\
*fixed* :D

PS: @Terminator: Use Thor's resource cache! :P
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

The Terminator

  • Full Member
  • ***
  • Posts: 224
  • Windows and Mac C++ Developer
    • View Profile
Re: Resource Manager
« Reply #4 on: July 26, 2012, 06:50:22 pm »
No it's ok guys, I got the thing sorted out and I threw my old design out and created a new one that actually works lol. Thanks for the help anyways.
Current Projects:
Technoport

 

anything