Why can't I overload functions from a base class?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

enum eTestB{ B };

class UseA{
public: void Testing( float Type ){}
};

class UseB : public UseA{
public: void Testing( eTestB Type ){}
};

void main(){
	UseB Var;

	Var.Testing( 0.5f );
}


Will result in a error "cannot convert param 1 from 'float' to 'eTestB'.

Why is this?
Last edited on
That is because what you have is not overloading, it is actually function hiding.

A function in a derived class that has the same name as a function in a base class hides ALL those functions with the same name in the base class.

Note:
It is not function overriding, because function overriding is for virtual functions
Ok thanks, I googled it for a solution and came to this page:
http://www.parashift.com/c++-faq-lite/strange-inheritance.html#faq-23.9

What is the standard way of taking care of this issue? By 'using' or by redeclaring the function in the derived class? Or some other way?
You have (at least) three possibilities - it all depends on what you want to achieve:

1. Rename the derived class function(s) to avoid the name clash

2. Use the using directive.

3. Redeclaring the function in the derived class, and in that function call the base class function.
This is useful, if you want to block direct access to the base class function, maybe you want to do something like make a log or maybe add some debugging code, then call the base class version.
By the way - that FAQ you found is really good - I use it quite often.
Topic archived. No new replies allowed.