calling virtual function results in calling function of base class ...

Discussion in 'C++' started by tiwy, Jan 9, 2005.

  1. tiwy

    tiwy Guest

    On Andreas Lagemann <> wrote:

    >
    > Class Base
    > {
    > public:
    > Base() {}
    >
    > Base(A* a, B* b);
    >
    > virtual A* foo(P* p, S& s); // using myA and myB


    Make sure you have a virtual destructor, private copy constructor and
    private assignment operator.

    > Executing this results in Base::foo being called instead of Der::foo


    Did you make a typo or something. It will call Der::foo if your foo
    signature is exact the same in Der.
    Are you sure you use pointers when you are passing the Der object as a
    Base object? To make sure use private copy constructor and private
    assignment operator so you will not lose the Der object info when
    copying the object.


    > (what I would expect) ....
    > What am I doing wrong ?


    Typo?

    > Is that because cstr of Der does not initialize any mebers of Base ?


    Nope


    Cheers Tim
     
    tiwy, Jan 9, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tomek
    Replies:
    2
    Views:
    681
    Andrey Tarasevich
    Dec 1, 2003
  2. tomek
    Replies:
    3
    Views:
    750
    David Fisher
    Nov 30, 2003
  3. Chunhui Han
    Replies:
    2
    Views:
    506
  4. Andreas Lagemann
    Replies:
    8
    Views:
    487
    Mike Wahler
    Jan 10, 2005
  5. Tinku
    Replies:
    3
    Views:
    1,178
    Alf P. Steinbach
    Jan 31, 2010
Loading...

Share This Page