www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

D - Return type overloading

↑ ↓ ← Marti <sip email.ee> writes:
Has function return type overloading been considered for D? It might be useful
for some scenarios.

For example, in the code::

int get2()
{
return 2;
}
float get2()
{
return 2.0;
}

the function body that gets called depends on the expected type of the value::

int i;
float f;

i = get2(); //the int version body of get2() is called
f = get2(); //the float version is called
f = cast(int)get2(); //the int version is called, and the value is implicitly
//casted to a float
f = cast(float)cast(int)get2(); //the int version is called, and the value is
//explicitly casted to a float

I'm not sure about what to do if the expected type can't be determined. Perhaps
we should require an explicit cast? Consider this::

f = 2 + get2();

I'm sure there are loads of other ambiguities I haven't thought about. I'm not
even sure if it's a good idea, but it's an idea worth considering nevertheless.

--
Marti
Jun 14 2004
↑ ↓ → Marti <sip email.ee> writes:
Oops, this message ended up in the old newsgroup. Please don't answer it here
and go to the post in digitalmars.D instead.

Sorry. :)

--
Marti
Jun 14 2004