c++ - Why does this code crash at the places mentioned? -


Can you please explain why this code crashes on that place? I'm a little stumped on this. I think it has got to do something with sizeof (int) , but I'm not completely sure what can anyone explain?

  class base {public: virtual zeros some functions (printf ("test base \ n"); } Int m_j; }; Category created: Public base {Public: Some functions (zero) {printf ("test derive \ n"); } Private: int m_i; }; Zero MyWonderfulCode (base baseArray []) {baseArray [0] .Somefunction (); // Works fine bassarre [1]. Some functions (); // Invalid due to vfptr baseArray [2] Crash. Some functions (); // Crash due to invalid vfptr baseArray [3]. Some functions (); // Works fine bassarre [4]. Some functions (); // Invalid due to vfptr baseArray [5] Crash. Some functions (); // Invalid vfptr baseArrest crashes [6] Some functions (); // Works fine bassarre [7]. Some functions (); // Crash due to invalid vfptr baseArray [8]. Some functions (); // Crash due to invalid vfptr baseArray [9]. Some functions (); // Works Fin} Int'tan (int arguments, TCHAR * AGRV []) {Derived Derivative Array [10]; MyWonderfulCode (derivedArray); Return 0; }  

Excerpt from this FAQ:

< P> is larger than the derived base, the pointer is done with the arithmetic 2 object base. It is wrong. The compiler uses the size (base) when calculating the address for the second object, even then the array is an array, which means Is that the address calculation (and later the voice does not even have a member function at the beginning of any object! This is a derivative Is a type of fish between the object


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -