Re: left handed use of conditional




"David Anton" <DavidAnton@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F50BB529-0D27-41E0-84B6-0639484B7B4B@xxxxxxxxxxxxxxxx
Regarding the 'other surprising cases'; are you sure there's no weird
compiler setting you have to have to get these to work?
I tried the following (your first case) and it won't compile:
class foo {
void test() {
int a, b;
(a < b ? f : g)(10);
}
void f(int i) {}
void g(int i) {}
};

--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter


Your class example also did not compile for me. However when I deleted the
class construct and moved the definitions for f() & g() to before test it
did compile:

int f(int i) { return i - 1;}
int g(int i) { return i + 1;}

int test(int i) {
int a=1, b=0;
return ((a < b) ? f : g)(i);
}

(I changed the return types to make sure it worked) and worked
wonderfully...

I am confused on why this didn't work from within the class. I did try a few
permutations of things to see if I could get it to work.

class foo {
int f(int i) { return i - 1;}
int g(int i) { return i + 1;}

int test(int i) {
int a=1, b=0;
return ((a < b) ? f : g)(i);
}
};

returns the error: "term does not evaluate to a function" in VC++ (VS6)
and even making it: ((a < b) ? foo::f : foo::g)(i);
did not resolve the problem.

and foo::((a < b) ? f : g)(i); is an nonsencical as it looks.

Even tried to define all of the functions outside of the class declaration
and it generates the same error.

Just when I think I am getting to the point where I understand things!!!


.



Relevant Pages

  • Re: pointer q
    ... int main (void) ... it would compile what you wanted was: ... a type compatible with the effective type of the object, ...
    (comp.lang.c)
  • Re: compiling error
    ... How to make it compile? ... void open_file ... int buf; ... Okay arrays when passed to function should not have the index but the ...
    (comp.lang.c)
  • Re: Writing to text segment
    ... memcpy((void *)&foo, buf, sizeof buf); ... Because it won't compile? ... volatile int i = 1; ...
    (comp.lang.c)
  • Please Help => Simple Program
    ... I am trying to compile a Visual Studio 2005 C++ project using an ... about converting from void* to float* because of the last 5 parameters ... in the "BiquadSections" structure. ... int main ...
    (microsoft.public.dotnet.languages.vc)
  • SUMMARY: void main(int argc, char *argv[]) question
    ... The consensus is that the use of void on main is wrong (The book ... return and int. ... >In trying to compile some old test Unix C programs... ... Why do those old UNIX programs used void ... ...
    (SunManagers)

Quantcast