Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   calling virtual function results in calling function of base class ... (http://www.velocityreviews.com/forums/t288041-calling-virtual-function-results-in-calling-function-of-base-class.html)

tiwy 01-09-2005 11:17 PM

calling virtual function results in calling function of base class ...
 
On Andreas Lagemann <andreas.lagemann@freenet.de> 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


All times are GMT. The time now is 04:29 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57