Hi everyone,
Now every error seems weird, but this one _really_ does to me ;-)
I have to classes, A and B. B is an interface for let's say B_a and B_b.
'A' contains a pointer to 'B', pointing to an allocated object of either 'B_a' or 'B_b' (via some factory), and the 'B-object' contains a pointer to A (some pimpl implementation).
Class 'A' also has a derived class, therefore some of it's member functions are virtual (and here's the problem).
Code:
class A;
class B {
public:
B(A* p_a) : a_(p_a) {}
virtual void read( 'file ') = 0;
protected:
A* a_;
};
class B_a : public B // class implements 'read'
class B_b : public B // class implements 'read' in a similar way as B_a (see below)
class A {
public:
A() : _b(new B_b(this)) {} // or new B_a(this) , this is done in some factory method
void read( 'file' ) { b_->read('file'); }
virtual void f();
virtual void g();
protected:
B* b_;
};
void B_a :: read( 'file' ) {
// do a lot of things specific for B_a (or B_b)
a_->f(); // someting weird happens here
// do a lot of other things specific for B_a (or B_b)
a_->g();
}
Now the weird thing is : the call 'a_->f()' does _not_ call 'A::f()' , but it call 'B::g()' !!
If I remove the keyword 'virtual' (temporarily) for 'A::f()' it works, but then it produces a similar error for the call 'a_->g()' . Unless I remove the keyword 'virtual' ....
** I have verified the adresses of the pointers, that's all correct. I am debugging the correct code, I verified with some 'asserts'.
** calling 'a_->f()' from another context just just just before 'B_a::read', does not produce the problem.
Is there somewhere a stack corruption ? If so, how could I detect it ?
Thanks a lot !!!