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

Author Topic: Creating an ImageManager class  (Read 2280 times)

0 Members and 1 Guest are viewing this topic.

loogie

  • Newbie
  • *
  • Posts: 3
    • View Profile
Creating an ImageManager class
« on: January 26, 2012, 08:43:34 pm »
Hi, I'm very new to c++ and c, and i'm attempting to make an image manager, preferably something that has static functions to retrieve the objects saved in it from any class...

(ie, you can call ImageManager::loadAsset() from the main function, and also ImageManager::getImage() from a sprite class to load the image instance...)

I understand that to make a "Static Class" you can place the constructor as private, but I'm having trouble retrieving the sf::Image to get an instance of the image loaded... here is a very simple example i'm trying.

Code: [Select]

#include <SFML/Graphics.hpp>

class ImageManager {
public:
   
    static const sf::Image& getImage();
protected:
   
private:
    ImageManager();
    virtual ~ImageManager();
    static sf::Image image;
};


and

Code: [Select]

#include "ImageManager.h"

ImageManager::ImageManager() {
}

ImageManager::~ImageManager() {
}

const sf::Image& ImageManager::getImage()
{
    sf::Image img;
    img.LoadFromFile("zeldatest.png");
   
    ImageManager::image = img;
   
    return ImageManager::image;
}


this gets the error

"ImageManager.cpp:21: undefined reference to `ImageManager::image'" but i have no idea how o fix it..  any insight in how to deal with static classes and properties etc would be greatly appreciated!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Creating an ImageManager class
« Reply #1 on: January 26, 2012, 08:59:07 pm »
That's a very basic C++ rule. Any tutorial/book/documentation/blog will give you the solution ;)
http://lmgtfy.com/?q=c%2B%2B+static+member
Laurent Gomila - SFML developer

tobybear

  • Newbie
  • *
  • Posts: 27
    • View Profile
Creating an ImageManager class
« Reply #2 on: January 26, 2012, 10:36:58 pm »
there are also several resource and image managers on the wiki/projects section of this site that you might check for reference .

 

anything