| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"dropy" |
| Date: |
28 Jul 2003 03:13:56 PM |
| Object: |
Overloading by return type and a parameter value |
Hi, this is a oversimplification of my problem:
I have two functions:
double foo(int param);
int foo(int param);
I want 'double function' to be called if param=1
and 'int function' if param=2
foo(1) => double foo(1)
foo(2)=> int foo(2)
Is this possible?
Thanks
.
|
|
| User: "Jonathan Mcdougall" |
|
| Title: Re: Overloading by return type and a parameter value |
28 Jul 2003 03:59:02 PM |
|
|
On Mon, 28 Jul 2003 22:13:56 +0200, "dropy" <dropy@dododo.com> wrote:
Hi, this is a oversimplification of my problem:
I have two functions:
double foo(int param);
int foo(int param);
I want 'double function' to be called if param=1
and 'int function' if param=2
foo(1) => double foo(1)
foo(2)=> int foo(2)
Is this possible?
A simple way would be
double d_foo();
int i_foo();
int foo(int param)
{
if (param == 1)
d_foo();
else if (param == 2)
i_foo();
}
Another way would be
template <int param> class foo;
template <>
class foo<1>
{
public:
double operator()( /* something */ )
{
// do something
}
};
template <>
class foo<2>
{
public:
int operator()( /* seomthing */ )
{
// do something
}
};
int main()
{
foo<1> f;
f(); // calls double operator()
foo<2> g;
g(); // calls int operator()
}
Jonathan
.
|
|
|
|
| User: "Artie Gold" |
|
| Title: Re: Overloading by return type and a parameter value |
28 Jul 2003 03:58:24 PM |
|
|
dropy wrote:
Hi, this is a oversimplification of my problem:
I have two functions:
double foo(int param);
int foo(int param);
I want 'double function' to be called if param=1
and 'int function' if param=2
foo(1) => double foo(1)
foo(2)=> int foo(2)
Is this possible?
Nope. You can neither overload by argument _value_ nor by return value.
HTH,
--ag
--
Artie Gold -- Austin, Texas
.
|
|
|
|

|
Related Articles |
|
|