overload

T

Tony Johansson

Hello!

I just wonder if it's possible to overload a method only by having a
different return type.

//Tony
 
V

Victor Bazarov

Phlip said:
Google "covariant return types".

You may be thinking "override". The question, however, is about
"overload". The answer is still "no", Larry is correct.

V
 
P

Phlip

Pete said:
Phlip wrote:
No need. His answer is right. Read the question again. <g>

"Overload" would mean "within the same scope", but only if C++ directly
supported the "method" concept. It doesn't, we are fuzzy, and so "No" is too
short an answer.
 
P

Pete Becker

Phlip said:
Pete Becker wrote:




"Overload" would mean "within the same scope", but only if C++ directly
supported the "method" concept. It doesn't, we are fuzzy, and so "No" is too
short an answer.

Huh? "Overload," as it's defined in C++, only applies to names declared
"within the same scope." Doesn't matter whether C++ directly supports
the "method" concept, whatever that is.

But if you're right, then please point out at least one context in C++
in which overloading can be based solely on the return type.
 
A

Alf P. Steinbach

* Phlip:
"Overload" would mean "within the same scope",

Depending on what that means (?), a counter-example:

struct A
{
void foo() {};
};

struct B: A
{
using A::foo;
void foo( int ) {}
};

but only if C++ directly supported the "method" concept.
???


It doesn't, we are fuzzy,
???


and so "No" is too short an answer.

Yes, it would be prudent to include discussion of template functions
and also the dummy argument trick. However, most of us are usually too
lazy to go into the "what's probably the reason for the question and the
ways that can be achieved". At least, I am. ;-)
 
P

Phlip

Pete said:
But if you're right, then please point out at least one context in C++
in which overloading can be based solely on the return type.

What I'm "right" about is the question is fuzzy, hence you can't just answer
"No".

I assure you I agree with you both, to the letter, on the details of
overloading and differing return types.
 
P

Pete Becker

Phlip said:
Pete Becker wrote:

Please be more careful with your attributions. That "sigh" was yours,
not mine.
What I'm "right" about is the question is fuzzy, hence you can't just answer
"No".

Only if you're trying to obfuscate, which, given the doubletalk you
posted in your initial response, may well be the case. Those of us who
gave useful answers know exactly what the question meant.
 
P

Phlip

Pete said:
Only if you're trying to obfuscate, which, given the doubletalk you
posted in your initial response, may well be the case.

My initial response was 'Google "covariant return types".'
 

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
474,204
Messages
2,571,064
Members
47,672
Latest member
svaraho

Latest Threads

Top