Jump to content
  • Advertisement
Sign in to follow this  

Class Initializer

This topic is 2234 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a class with members as follows:

typedef void (*size_fn)(int, int);
typedef void (*key_fn)(InputType, int);
typedef void (*pointer_fn)(InputType, int, int);

typedef std::hash_map<const void*, size_fn> size_handle_c;
typedef std::hash_map<const void*, key_fn> key_handle_c;
typedef std::hash_map<const void*, pointer_fn> pointer_handle_c;

size_handle_c size_handles;
key_handle_c key_handles;
pointer_handle_c pointer_handles;

And am trying to initialize them in the constructor as follows:

EventManager* EventManager::instance = NULL;

: size_handles(), key_handles(), pointer_handles()
instance = this;

Problem is, when I go to handle an event:

void EventManager::FirePointer(InputType type, int x, int y) const
if(pointer_handles.size() == 0) return;

pointer_handle_c::const_iterator i = pointer_handles.cbegin(); //Access violation
pointer_handle_c::const_iterator e = pointer_handles.cend();

while(i != e) i++->second(type, x, y);

I get an access violation at the indicated line. It looks like all my hash_maps are also basically uninitialized. Did I completely miss something in construction?

Share this post

Link to post
Share on other sites
False alarm. The problem ended up being in a completely different place:

EventManager* EventManager::GetInstance()
if(EventManager::instance) EventManager::instance; //Should be if(EventManager::instance) return EventManager::instance;

return EventManager::instance;


Share this post

Link to post
Share on other sites
For future reference, this code:

class Foo
: Member_Bar()
{ }

Is precisely identical to this code:

class Foo { };

All of your members are default-constructed unless otherwise specified.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!