visual studio 2005 - Invalid ESP when using multiple inheritance in C++ (VS2005) -


I am creating a game that uses a box 2D physics engine, and I have some strangeity with the stack pointer (ESP) and Multiple Succession I have reproduced it in the minimum code, and it seems that in the order in which I declare the classes used in many heritage, it decides whether the program crashes Whether or not they are.

  # include & lt; Iostream & gt; #include & lt; String.h & gt; using namespace std; Class IFFixics Object {Public: Virtual Zero Collide (IFeXix Object * Other, Float Angle, Int Pauses) = 0; }; Square iBoordFeature {public: IBORDFeature () {}; ~ IBoardFeature () {}; Virtual Bull Onet (int x) {returns true; } Virtual bool update (int x, float dt) = 0; }; / * Class CScorezone: Public IBoardFeature, Public IPhysicsObject // Break it !!! Class CScorezone: Public IFGics Object, Public IBoardFeature // It Works !! * / Class CScorezone: public IBoardFeature, public IPhysicsObject {public: CScorezone () {} ~ CScorezone (zero) {} Virtual bool update (int x, float dt) {back true; } Virtual Zero Colloid (IPhysicsObject * Other, Float angle, int pauses) {} Virtual Bull Onet (int x) {Back true; }}; Int main (int argc, char * argv []) {CScorezone * scoreZone = new CScorezone (); CScorezone * other zones = new CScorezone (); Zero * voidZone = scoreZone; IPhysicsObject * physZone = static_cast & lt; IPhysicsObject * & gt; (Zero zero); Phiz- Anon-> Colloid (second zone, 10, 1); Delete ScoreZone; Delete others; // Wait for user input int x; Cin & gt; & Gt; X; Return 0; }  

Running in debug mode causes the following error

Run-time check failure # 0 - ESP values ​​in a function properly Was not saved This is usually the result of calling a function called a function pointer with a calling conference, which is declared with a different calling conference.

When I go to the following line of code:

  Fiz-Zone-> Colloid (other zone, 10, 1);  

I think this is not going on in CScoreZone :: OnAttach, CScoreZone :: Collide. Why is it like this? I change sequence of inheritance for CSSERZone, it works fine

  class CScorezone: public IPhysicsObject, public IBoardFeature  

running on VS2005 SP2 Am 8.0.50727.768) Any ideas on Windows XP?

The problem is that you insert the pointer to zero first * first. The compiler does not know how to cast static for pointer. If you use multiple heritage to use the second superclass virtual table, then it will need to change the pointer value during artists. Just put the pointer back to CScoreZone * before using static_cast.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -