This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: compiler confusion?


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 at synaptics-uk dot 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]