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: 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









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