Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Polymorphism and inheritance

Reply
Thread Tools

Polymorphism and inheritance

 
 
Bart Friederichs
Guest
Posts: n/a
 
      09-08-2008
Hello,

I created the following inheritance:

class Parent {
public:
void foo(int i);
};

class Child : public Parent {
public:
void foo(int i, int i);
};

The following code fragment does not work (it doesn't compile, g++
complains about 'no matching function call for Child::foo(int)':

....
Child c;
int k = 0;
c.foo(k);
....

I assumed that by inheriting the base class, the 'Child' class would
have two 'foo' methods, with different parameters. Apparently not. Adding

void foo(int i) { Parent::foo(i); }

to the Child class, fixes it, but is that how it should be done? Why is
the Parent's foo() not polymorphised-inherited by Child?

TIA,
Bart
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Static Class Variables, Inheritance, and Polymorphism crjjrc C++ 8 04-05-2007 08:39 PM
Dynamic polymorphism vs. Static polymorphism Krivenok Dmitry C++ 13 06-01-2006 09:49 AM
I need help with "Inheritance" and "Polymorphism" Fao C++ 13 05-01-2006 11:55 PM
Inheritance, polymorphism, and introspection in Python combinational.logic $ soc-ip.com Python 0 05-27-2005 05:36 PM
trying to understand Inheritance, Polymorphism and templates sapropel C++ 1 05-14-2004 02:25 PM



Advertisments
 



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