B
Bart Friederichs
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
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