This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Is this a bug or I misunderstand?
- From: "maggie_shh" <maggie_shh at hotmail dot com>
- To: "Andrew Pinski" <pinskia at physics dot uc dot edu>
- Cc: <gcc at gnu dot org>
- Date: Mon, 17 Jun 2002 14:34:08 +0800
- Subject: Re: Is this a bug or I misunderstand?
- References: <24E17386-81B9-11D6-A42F-000393122612@physics.uc.edu>
but If I change "A b();" to "A b(1);",It will be right and the behaviour is
as I had said.
It show us that the c++ compiler do not take it as local function
declaration.
btw:Is it useful to declare a function in another function?As I know,C++
standard forbide
function definition in another function,but permit function declaration in
function scope.
but
If we want to use another function out of current file scope,we can declare
it outside of function.
It will not change the behaviour of our codes.
Best Regards
Maggie
----- Original Message -----
From: "Andrew Pinski" <pinskia@physics.uc.edu>
To: "Maggie Mitchell" <maggie_shh@hotmail.com>
Cc: <gcc@gnu.org>
Sent: Monday, June 17, 2002 2:12 PM
Subject: Re: Is this a bug or I misunderstand?
> This is common mistake for beginners of c++ and some advance c++ people.
> The problem is the statement `A b();' is not a statement declaring a
> variable with type of b and using the default constructor but rather
> declaring a function that takes no variables and returns an `A' object.
>
>
> Thanks,
> Andrew Pinski
>
>
> On Monday, June 17, 2002, at 01:55 , Maggie Mitchell wrote:
>
> > //The codes begin
> > #include <stdio.h>
> > class A {
> > public:
> > A(int i=0)
> > {
> > printf("hello\n");
> > }
> > };
> > int main()
> > {
> > printf("begin\n");
> > A a;
> > printf("----\n");
> > A b();
> > printf("end\n");
> > return 0;
> > }
> > //codes end
> > I think the result should be
> > begin
> > hello
> > ------
> > hello
> > end
> >
> > but the result is
> > are
> > begin
> > hello
> > -----
> > end
> >
> > why?Is It a bug of g++ or I misunderstand the behaviour of constructor?
> >
> > Regards
> > Maggie
> >
> >
> > _________________________________________________________________
> > Send and receive Hotmail on your mobile device: http://mobile.msn.com
> >
> >
> >
>