c++ - How to pass the instance itself to an external map at the moment of its creation? -


i have class object , typedef:

class object { private:     long int id; public:     object(void);     ~object(void) {};     long int get_id(void); };  typedef map<long int, object> obj_map; 

and have class app, has obj_map , object_counter:

class app { public:     static allegro_display *display;     static allegro_event_queue *event_queue;     static allegro_timer *timer;     static allegro_event e;     static bool running;     static bool redraw;     static key_map key_states;     static obj_map objects; // << here.     static long int object_counter; // << here.     const char *window_title;     int screen_width;     int screen_height;     float fps;     act event_scenes;     act visual_scenes;     allegro_color background_color;      static allegro_event event();     static allegro_event_type event_type();     static void shut_down();      app(int screen_width, int screen_height, const char *window_title = "joy++ application", float fps = 30);     ~app() {};      int init_all();     void register_all();     void check_key_states();     void init_key_states();     void run();     void destroy_all();     void add_event_scene(scene scene);     void add_visual_scene(scene scene);     void remove_event_scene(scene scene);     void remove_visual_scene(scene scene);      long int get_object_count();     unsigned int get_random_int(unsigned int min, unsigned int max);     void set_key_state(int al_key, string key_name, bool state);     void set_background_color(int r, int g, int b); }; 

as can see, idea store every object inside app, under id, inside map. but, want happen @ moment of creation of each object. here's constructor definition:

object::object() {     app::object_counter += 1;     this->id = app::object_counter;     app::objects[this->id] = this; // problem. } 

error:

g:\development\game-development\cb\joy-plus-plus\app.cpp|26|error: no match 'operator=' (operand types 'std::map<long int, object>::mapped_type {aka object}' , 'object* const')| 

how can pass instance of each object external map @ moment of creation?

if object has value semantic assign *this (the object) , not this.

on other hand if identity counts build map object * (or, better std::shared_ptr) , assignment work is


Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -