gdb zeigt unkorrekte Variablenwerte
-
Hi,
ich arbeite mit Eclipse 3.3 unter Linux und verwende den gdb. Ich habe folgende Klassen definiert:
class node { public: virtual void f() = 0; int id; }; class tip : public virtual node { void f() {}; }; class recomb_node : public virtual node { void f() {}; }; class recomb_tip : public virtual node, public tip, public recomb_node { public: void f() {}; recomb_tip(); }; recomb_tip::recomb_tip() { }
Mein Hauptprogramm sieht wie folgt aus:
#include "node.h" #include <iostream.h> int main(int argc, char** argv) { node* n = new recomb_tip(); n->id = 1; tip* m = dynamic_cast<tip*>(n); recomb_node* k = dynamic_cast<recomb_node*>(n); cout << m->id << endl; cout << k->id << endl; return (EXIT_SUCCESS); }
Als Ausgabe erhalte ich - wie zu erwarten - beides mal 1. Seltsamerweise bekomme ich im Debugger am Ende von main angezeigt, dass k->id = 0 und m->id = 1. Wenn man in der Definition von recomb_tip statt
class recomb_tip : public virtual node, public tip, public recomb_node
nun
class recomb_tip : public virtual node, public recomb_node, public tip
schreibt, dreht es sich um (k->id = 1 und m->id = 0).
Hat irgendjemand eine Erklärung hierfür?