"Andreas Lagemann" <> wrote in message
news:41e1796d$0$30345$...
> Hi,
> after browsing FAQ and archive for a while I decided that the following is
> a legal question.
>
> Consider this:
>
> Class Base
> {
> public:
> Base() {}
>
> Base(A* a, B* b);
>
> virtual A* foo(P* p, S& s); // using myA and myB
> protected:
> A* myA;
> B* myB;
> };
>
> class Der : public Base
> {
> public:
> Der(O* o) : Base(), myO(o) {}
> A* foo(P* p; S& s); // not using myA and myB
> private:
> O* myO;
> };
>
> class Bogus
> {
> public:
> Bogus(Base* b) : myBase(b) {}
>
> void bar()
> {
> ...
> myBase->foo(p,s);
> ...
> }
> private:
> Base* myBase;
> };
>
> int main(/*args*/)
> {
> ...
> Der der(someO);
> Bogus* bogus = new Bogus(der);
> ...
> bogus->bar();
> ...
> };
>
> Executing this results in Base::foo being called instead of Der::foo (what
> I would expect) ....
> What am I doing wrong ?
> Is that because cstr of Der does not initialize any mebers of Base ?
> How could I possibly avoid that or get the behaviour I need ?
> Pleas help!!!
>
> Regards,
>
> Andreas Lagemann
Looks like things are a bit muddled here?
What you're trying to do *should* work. If you have a class that has a
Base* pointer, and you initialize that pointer with the address of a Der
object, then when that class (Bogus) calls a virtual function using its
Base* pointer, it will resolve to the correct call in the Der class.
So, something is wrong with what you've shown.
As Mike suggests, try a simpler example first to be sure you know what is
happenning. Then you can implement it in a more complex environment.
(One other thing: if you're using VisualC++ 6, upgrade to 7. VC++ 6 is not
very standard-compliant. I don't know in which areas exactly, but it's
*possible* this could be one of them...?)
-Howard