Advertisement

pointer to function in a other object.

Started by November 14, 2005 10:46 AM
2 comments, last by Lennings 19 years ago
I get a error when i start the game. I guess it has something to do with my pointers. the ball instance have a ponter to mouse. " Unhandled exception at 0x0044fe60 in Gravitation.exe: 0xC0000005: Access violation reading location 0xcdcdcdd1. " some code . -------------------------------------------------- class Ball { public: Ball(sgl::Image *ballImage, Mouse *mouse); void update(const float& time); private: Mouse *m_mouse; sgl::Image *m_ballImage; unsigned int m_mousePosX }; --------------------------------------------------- class Mouse { public: Mouse(sgl::Image *mouseImage); unsigned int getMousePosX(); // have tested with "unsigned int&" it did't work. private: sgl::Image *m_mouseImage; unsigned int m_mousePosX; }; ----------------------------------------------------- and in the Ball.cpp file I got a commando m_mousePosX = m_mouse->getMousePosX(); what I what is to get the mouse cordinats to the ball. some idea, or maby a better way.
The idea is allright. I presume the member variable m_mouse is incorrectly initialized. In your design, in the constructor of Ball make sure the passed parameter mouse is stored in the member variable m_mouse. If already done, than check if the passed parameter is a valid instance.

Illco
Advertisement
t8... I will take a lock on it....
found the error.. i created the m_mouse after m_objectManager so i send a bad adress with m_objectManager. sow it was just to swap the lines.


m_imagesLoader = new ImagesLoader;
m_hud = new Hud;
m_mouse = new Mouse(m_imagesLoader->m_mousePointerImages);
m_objectManager = new ObjectManager(m_imagesLoader, m_mouse, m_hud);



t8 for the help....

This topic is closed to new replies.

Advertisement