C++ reluctant to overload function

V

Victor Bazarov

Since this thread has already mentioned Ada as an example of a language
where this kind of non-hiding can happen, perhaps it is apropos to
explain what would happen in Ada for this example:

Adding the function Base::f would make the call d.f(3) ambiguous, since
the compiler could not decide if the literal "3" should be taken as
integer or long-integer. Thus the compilation would fail, and the
programmer would have to say explicitly which type should be used for
"3", and this would determine if the call is to Base::f or to Derived::f.

So this example would "work" (be safe) in Ada because Ada does not have
the wide range of automatic type conversions and the "best match"
ambiguity resolver that C++ uses.

(I'm a habitual Ada programmer who is now trying to learn more about
C++. From my perspective, the automatic type conversions in C++ are
rather hair-raising :)

This is all a matter of personal preference, I would guess. Thirty
percent of countries in the world have cars normally moving on the left
side of the road. I find that rather hair-raising, and they do it every
day without even blinking.

Let's not submerge ourselves in feature bashing or language comparison,
shall we? Never does anything good come out of any of those
"discussions" here or in any other place.

V
 
J

Juha Nieminen

Victor Bazarov said:
Overloading is based on the *type* of the function, not the name,
although it does require the name to be the same. Another major
requirement for overloading is that both *names* have to be declared in
the same *scope*. In the original post the functions are declared in
different scopes, and overloading does NOT apply, and hiding does. Such
is the design of the language. What is it exactly that you don't
understand? The rationale for what?

I understand how it works. What I don't understand is *why* it has been
standardized to work like that.
 
V

Victor Bazarov

Victor, chill out! That sure looked to me like a neutral comparison of
how two languages address this issue, and it was quite helpful to me.

I'll chill out when I think it's time to chill out, thank you. My
suggestion was directed at the "automatic type conversions in C++" note
and *not* at the comparison of function overloading/hiding in C++ and
Ada (which was what you found helpful, I suppose). We've seen some
lunatics jumping on any chance to start complaining about different
aspects of C++, warranted or not, and all those characters need is a
whiff of a "don't get me started on <blah>" to actually start the
bashing. Just trying to avoid wasting the bandwidth.

V
 
V

Victor Bazarov

I understand how it works. What I don't understand is *why* it has been
standardized to work like that.

Just to remind: here we discuss "what", "where" and "how", and "why" is
usually discussed down the corridor, on the right, in 'comp.std.c++'.
Speaking of "why", quite a few features comprising the foundation of C++
are described and explained in "Design and Evolution of C++", do you
have a copy? I don't have mine handy, or I'd leaf through it to see if
function overloading is covered in it. I'd expect it to be.

V
 

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
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top