compiler confusion?
wilson k.j
wilson_kjacob@yahoo.com
Fri Apr 25 09:00:00 GMT 2003
But why it heppens only when you pass it ( g() == 100
) to constructors. I can have a method in struct A
with takes bool as argument, and invoke the method
like this,
objectOfA.myMethod( ( g() == 100 ) )
Wilson
--- Gareth McCaughan <gmccaughan@synaptics-uk.com>
wrote:
> Here's a stripped-down version of your code that
> exhibits
> the same problem.
>
> struct A {
> A(bool x) {}
> };
>
> struct C {
> void f();
> };
>
> static int g() { return 1; }
> void C::f() {
> A(g() == 100);
> }
>
> Here's what I think is going on: the compiler is
> seeing
> that line "A(g() == 100);" as a declaration of a
> function
> called g, returning a value of type A. The same as
> if it said
> "A g() == 100;". And, of course, when it gets to the
> "==",
> that stops making any sense :-).
>
> I'm not enough of a C++ standards guru to know
> whether
> this behaviour is (1) allowed and/or (2) required.
> It's
> weird, certainly, but there are other almost equally
> ludicrous interpretations that *are* required by the
> standard. For instance, here's an example from Scott
> Meyers's
> "Effective STL".
>
> ifstream dataFile("ints.dat");
> list<int> data(istream_iterator<int>(dataFile),
> istream_iterator<int>());
>
> Perhaps contrary to appearances, what this does is
> to declare a function called "data" taking two
> arguments: the first is of type
> istream_iterator<int>
> and is named "dataFile", and the second is of type
> "pointer to function from void to
> istream_iterator<int>"
> and has no name. :-)
>
> --
> g
>
>
>
__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com
More information about the Gcc
mailing list