Re: [Dev-C++] function overloading ambiguity
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <or...@vp...> - 2004-05-02 11:17:07
|
Oscar wrote:
> --- Code ---
>=20
> #include <iostream>
> #include <string>
>=20
> using namespace std;
>=20
> typedef enum boolean {false, true};
> void Teststr(string& str )
> {
> cout << "Function called, type: 'string'" << endl;
> cout << " Value:" << str << endl;
> }
>=20
> void Testint( int i )
> {
> cout << "Function called, type: 'int'" << endl;
> cout << " Value:" << i << endl;
> }
>=20
> void Testboolean( boolean b )
> {
> cout << "Function called, type: 'boolean'" << endl;
> cout << " Value:" << b << endl;
> }
>=20
> int main()
> {
> Teststr( "This is some text" );
> Testint( 12345 );
> Testboolean( true );
>=20
> return 0;
> }
>=20
> --- Code End ---
This would be the most obvious solution, but in this case, not even the=20
"boolean" enumeration is needed, as there is no overloading.
Besides, I already considered having three different functions and no=20
overloading, but I thought overloading is a more "elegant" solution in=20
my case (I've just finished writing a small general purpose=20
section-based configfile reader/writer, in case anyone's interested)
--
Greetings,
Bal=E1zs
|