In message <a3**************************@posting.google.com >,
marco_segurini <ma***********@virgilio.it> writes
"Sumit Rajan" <su********@yahoo.com> wrote in message
news:<2r*************@uni-berlin.de>... "marco_segurini" <ma***********@virgilio.it> wrote in message
news:a3**************************@posting.google.c om... > Hi,
>
> I am wondering if there is a way to use the ternary operator to select
> a function, between two, even if at least one of them is overloaded.
> Ex:
>
> void f1(int) {}
> void f1(double) {}
> void f2(int) {}
> //void f2(double) {}
>
> int main()
> {
> bool bTest = false;
> (bTest ? f1 : f2)(int(1)); // this statement does not compile
bTest ? f1(int(1)) : f2(int(1));
Thanks for your reply Sumit.
This solution is the same as use:
if (bTest)
f1(1);
else
f2(1);
My goal is to avoid to repeat the actual parameters list (1).
You need a typedef to disambiguate the pointer to the overloaded
function:.
typedef void (*FInt)(int);
typedef void (*FDouble)(double); // etc
(bTest ? FInt(f1) : FInt(f2)) (1);
--
Richard Herring