Overloading based on return type

M

Madhav

Hi All,
Very recently I had one iteresting question about
overloading. The guy was arguing why we dont have overloading based on
return type. I told him about the reason mentioned in "Thinking in C+
+", which is what if the return type is ignored by the caller.

He then said that the regular overloading places
restrictions - such as same fucntion names, different type or number
of arguments. If the language creators wanted to implement
overloading, they could have forced the restriction of specifiying the
return type each time the caller ignores that function.

I request everyone to comment on this. I really want to find
out why overloading is not supported on the basis of return type of
the function.

Regards,
Madhav.
 
T

tony_in_da_uk

I really want to find
out why overloading is not supported on the basis of return type of
the function.

Google's a wonderful thing - from Stroustrup himself:

The reason that C++ doesn't allow overload resolution based on a
return
type (so that you need to use explicit qualification in the examples
below) is that I wanted overload resolution to be bottom up. For
example, you can determine the meaning of a subexpression a+b without
considering the complete expression that a+b is part of. Overload
resolution can be subtle so even though I knew how to use return types
as part of resolution (Ada showed how), I decided not to. As a result
of this decision, a+b means the same in a+b+c as in a+b+d. See
Stroustrup: The Design and Evolution of C++ for more details of the
design of C++.
 

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

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top