S
shikn
I wrote one simple piece of codes to test const objects in C++ as below:
=================================
class Empty{};
main()
{
const Empty e1;
}
==================================
I built this with g++(version 3.2.2 20030222), the compiling result is:
======================================
$ g++ empty.C
empty.C: In function `int main()':
empty.C:5: uninitialized const `e1'
======================================
Many books on C++ said compiler shall automatically generate one default
constructor
for one class if there is no constructor in codes, so the statement "const
Empty e1"
should invoke the constructor that compiler generates for the class.
But why the compiler still reports "uninitialized const "?
If I change the statement as this: const Empty e1( ), the compiling shall
pass.
Thanks in advance!
=================================
class Empty{};
main()
{
const Empty e1;
}
==================================
I built this with g++(version 3.2.2 20030222), the compiling result is:
======================================
$ g++ empty.C
empty.C: In function `int main()':
empty.C:5: uninitialized const `e1'
======================================
Many books on C++ said compiler shall automatically generate one default
constructor
for one class if there is no constructor in codes, so the statement "const
Empty e1"
should invoke the constructor that compiler generates for the class.
But why the compiler still reports "uninitialized const "?
If I change the statement as this: const Empty e1( ), the compiling shall
pass.
Thanks in advance!