Thank you. Your answer is very clear.
Alf P. Steinbach wrote:[color=blue]
> *
nan.li.g@gmail.com:[color=green]
> >
> > class A
> > {
> > public:
> > //A() { }
> > };
> >
> >
> > int main()
> > {
> > const A a;
> > return 0;
> > }
> >
> > The compiler should generate a default constructor for me and the
> > default one shoule be no different than the one I specified. Why do I
> > have to specify one in this code?[/color]
>
> Look at the error message which you have repeated as subject line.
>
> It's not meaningful to have a constant without a specified value.
>
> You're lucky: Visual C++ 7.1 erronously compiles the above without
> flagging the error.
>
>[color=green]
> > [nan@athena test]$ g++ test19.cpp
> > test19.cpp: In function `int main()':
> > test19.cpp:10: error: uninitialized const `a'[/color]
>
> In the code as-is no value is provided for the constant, and
> according to §8.5/9 the program is "ill-formed".
>
> You can (1) initialize explicitly, e.g..
>
> A const a = {};
>
> (allowed only for aggregate type, which A is) or
>
> A const a = A();
>
> Or you can (2) define your own default constructor.
>
> Any way you need to explicitly define the value of the constant.
>
> --
> A: Because it messes up the order in which people normally read text.
> Q: Why is it such a bad thing?
> A: Top-posting.
> Q: What is the most annoying thing on usenet and in e-mail?[/color]