inheritance / overloading

M

Maurice Termeer

suppose i've got the following:

class a {
public:
virtual void f(int a);
};

class b : public a {
public:
void f(int a, int b);
};

Now I expected that if I had an object o of type b and I would call
o.f(1); that the method of class a would be invoked. However, if I try
this, the compiler says 'b::f does not take one parameter' (msvc++ 2005
beta 2).

How can I solve this? I want o.f(1) to call the method of a, and o.f(1,
2) to call the method of b.

Thanks in advance,

Maurice Termeer
 
S

Sharad Kala

Maurice Termeer said:
suppose i've got the following:

class a {
public:
virtual void f(int a);
};

class b : public a {
public:
void f(int a, int b);
};

Now I expected that if I had an object o of type b and I would call
o.f(1); that the method of class a would be invoked. However, if I try
this, the compiler says 'b::f does not take one parameter' (msvc++ 2005
beta 2).

How can I solve this? I want o.f(1) to call the method of a, and o.f(1,
2) to call the method of b.

This is what Comeau online tells me - "warning: function "a::f(int)" is
hidden by "b::f" --virtual function override intended ? Check the FAQ at
http://www.parashift.com for more details on this. To make a::f visible in b
write this -
class b : public a {
public:
using a::f;
^^^^^^^
....
};

Sharad
 
M

Maurice Termeer

Sharad said:
This is what Comeau online tells me - "warning: function "a::f(int)" is
hidden by "b::f" --virtual function override intended ? Check the FAQ at
http://www.parashift.com for more details on this. To make a::f visible in b
write this -
class b : public a {
public:
using a::f;
^^^^^^^
...
};

thanks! i've never used the using keyword in this context before.. and
that really is a nice reference. too bad i can't download it for offline
viewing anymore.

and quite nice that the problem was listed under "what your mother never
told you" and the whole "it means you're going to die" thing.

Maurice
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,498
Latest member
log5Sshell/alfa5

Latest Threads

Top