My question is, doesn't compiler provide the default constructor when we declare an object of type const?
There is no such limitation. The above code compiles under Visual Studio 2003.
PS.
But if you have a data member in the class, things should be different. That is because if you are not initializing data while creating the object, you can't change any of it later.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Maybe Visual C++ allows objects of classes without data members to be declared const even when a constructor is not defined. Because there are no data members, there is no data to be initialized so there is nothing wrong with it. But VC gives a warning when objects of classes with data members are declared const without a proper constructor.
On the other hand g++ apparently doesnt give any room whether the class has data members or not.
I would quote the apporoprite portion of the C++ standard to find what it has to say about this, but I am a bit pressed for time.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115