Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5987911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:52:59+00:00 2026-05-22T22:52:59+00:00

I have a class imgmanager that allows me to load all my images exactly

  • 0

I have a class imgmanager that allows me to load all my images exactly once, it’s quite nice, and while prototyping I had all of my files in one place, so I didn’t have to worry about cyclical definitions. However after separating all of my classes I have a problem.

My Header File

#ifndef IMAGEMANAGER_H   
#define IMAGEMANAGER_H
#include "Img.h"
#include <vector>
#include <map>
#include <string>

class imgmanager{
 protected:
 std::vector<sf::Image*> images;
 std::map<std::string,int> positions;
 public:
 sf::Image* addimg(std::string path); //relative to resources
 sf::Image* getimg(std::string path);
 int size();
 virtual ~imgmanager();
 sf::Image* operator[](int);
}imagemgr;

#endif

With the instance created after the } and before the ; my compiler complains at me:

So I ask: What should I do to have a global instance of my imagemgr class? Should I just make a global header file and create an instance? (in this particular case I can just make a global variable in my main.cpp, none of the headers require the instance)

Problem Screencap

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:53:00+00:00Added an answer on May 22, 2026 at 10:53 pm

    Don’t create object instances in headers.

    Create your object instance in one source file.

    If you need to access it across multiple Translation Units, put this in your header:

    extern imgmanager imagemgr; // declaration
    

    This will inform all code that can “see” the header that there exists a so-named object; but it will still only actually be defined in the one source file where you wrote:

    imgmanager imagemgr; // definition
    

    (This is analogous to the way in which you declare functions in a header, but define them in precisely one source file:

    void f(); // declaration
    void f() { ... } // definition
    

    )


    The above general advice dutifully imparted, I would now question the rationale of having a class at all if you’re only going to use one, single, global instance of it. Either make it a “singleton” class, or use free functions in a namespace instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have class that extends BroadcastReceiver and gets all new sms. When I get
I have class that extend FragmentActivity in it I add fragment to layout as
I have class grades that I need to check if a specific grade is
I have class that looks like this: class A { public: class variables_map vm
I have class ParentClass that observes an NSNotification. ParentClass handles the notification. ChildClass inherits
I have class class DateOptTimeType implements org.hibernate.usertype.UserType that works with two columns @org.hibernate.annotations.Type(type =
I have class MasterData whose instances contain some general information about all possible gadgets.
I have class B that has class A, this is simplified version of class
I have class instantiated in a web service that, in a static member, holds
I have class for iterating images. public class PictureManager { private int _current; public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.