c++ - Why is my base class variable undefined at runtime? I'm initializing it from child classes -


i have parent class has variable populate child classes. @ runtime, expression seems never populated. isn't null. it's random thing ide says "expression cannot evaluated." i've stepped through initialization code, , seems initialize correctly. when call variable later @ runtime, throws it's hands in air , says has no idea is.

the base class:

namespace events {   class messagereceiver;    class messagejoint   {   public:     messagejoint( ogre::string id, messagereceiver* receiver );       void fireevent( messagereceiver* );      void setdata( boost::any d ){ data = d; }     void setidentifier( ogre::string id ){ identifier = id; }     virtual void handleevent( boost::any ) = 0;      void tunein( messagereceiver* r )     {       listeners.push_back( r );     }      ogre::string getidentifier(){ return identifier; }      messagereceiver*                  owner;     std::vector< messagereceiver* >   listeners;     boost::any                        data;    private:     ogre::string                      identifier;   }; } 

a child class consumes base class:

  class jointclosemenu : public events::messagejoint   {   public:     static const ogre::string cjointclosemenuid;     jointclosemenu( events::messagereceiver* receiver ) : events::messagejoint( cjointclosemenuid, receiver ){}     void handleevent( boost::any ); #define jointclosemenuname ogre::string("jointclosemenu")   }; 

here's how i'm initializing it. can see i'm setting value of identifier twice!

events::messagejoint::messagejoint( ogre::string id, messagereceiver* receiver )       : identifier( id ), owner(receiver), data( 0 ) { setidentifier( id ); } 

and here's function blows up. goes in messagejoint::getidentifier, , inside there, finds identifier not valid memory address. ide says expression cannot evaluated:

void events::messagejoint::fireevent( messagereceiver* ) {   ogre::string blah = getidentifier(); //<--kaboom!!!!   message m( from->getmyaddress(), owner->getmyaddress(), getidentifier(), &data );    eventmanager::getinstance()->messagedispatch( m );   //} } 

i forgot explain how i'm initializing cjointclosemenuid. in implementation file jointclosemenu class, initialize name of string so:

const ogre::string cjointclosemenuid; 

so figured out problem was. classes fine. accessor using reach container passing value, not reference. so, add instances container via accessor, , discarded when copy of container went out of scope. when code got around attempting use instance of class, had been destructed. doh!


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -