Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #4627

Re: Strange gcc compiler error?

From Victor Bazarov <v.bazarov@comcast.invalid>
Newsgroups comp.lang.c++
Subject Re: Strange gcc compiler error?
Date 2011-05-03 13:01 -0400
Organization A noiseless patient Spider
Message-ID <ippcd5$5a7$1@dont-email.me> (permalink)
References <47dc9f45-a4a5-4b61-aaf2-92c1602cc1cf@i39g2000prd.googlegroups.com>

Show all headers | View raw


On 5/3/2011 12:51 PM, J Cook wrote:
> Can anyone explain this error?  It seems as if the compiler is using
> the name of the first parameter as the temporary object name?
>
> class Foo
> {
>    Foo(int s) {}
>
> };
>
> void foo()
> {
>   int test = 4;
>   Foo(test);  // create a temporary. Thinks it is named "test" ??
> }
>
> int main()
> {
>    foo();
> }
>
> # In function 'void foo()'
> # error: conflicting declaration 'Foo test'
> # 'test' has a previous declaration as 'int test'
>
> gcc 4.1.2

In order to verify you could use www.comeaucomputing.com/tryitout (they 
compile but don't link), their compiler is very Standard-compliant.

As to your "error" since 'Foo' is the name of the type, the compiler can 
(and will) interpret

     Foo(test);

as a declaration of a variable 'test' of type 'Foo', thus trying to 
redeclare 'test' with another type.  To avoid that add parentheses

     Foo((test));

V
-- 
I do not respond to top-posted replies, please don't ask

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Strange gcc compiler error? J Cook <joecook@gmail.com> - 2011-05-03 09:51 -0700
  Re: Strange gcc compiler error? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-03 13:01 -0400
    Re: Strange gcc compiler error? J Cook <joecook@gmail.com> - 2011-05-03 10:06 -0700
      Re: Strange gcc compiler error? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-03 13:09 -0400
        Re: Strange gcc compiler error? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-05-03 13:10 -0400
          Re: Strange gcc compiler error? Öö Tiib <ootiib@hot.ee> - 2011-05-03 10:36 -0700
            Re: Strange gcc compiler error? James Kanze <james.kanze@gmail.com> - 2011-05-03 15:02 -0700
  Re: Strange gcc compiler error? Kai-Uwe Bux <jkherciueh@gmx.net> - 2011-05-03 19:31 +0200

csiph-web