Hi all, This time I have a doubt in C++ default constructors.In a site http://publib.boulder.ibm.com/infoc...bm.vacpp7a.doc/language/ref/clrc15cplr376.htm I read about default constructors.In that it is menctioned that No default constructor is created for a class that has any constant or reference type members. I did not understand this statement.i.e if no default constructor is created and also no user-defined constructors then what happens. Can anybody analyse this one for me. Thanks in advance. Regards, sharmila.
There is a small clairification on this. The statement should be : "No compiler generated (or implicit) default constructor is created for a class that has any constant or reference type members." What it means is, that for a class having Constant type of members, the Compiler doesn't create an implicit default constructor of its own, like it does otherwise. You must explicitly mention the default constructor for it to compile & work. Just try out a simple Class A with constant private members say 'x' & 'y', with a routine 'display( )' & WITHOUT a User-defined default constructor & then try compiling. U will recieve an error of the sort : 'A::x' in Class without constructors 'A::y' in Class without constructors Now, just compile the same, by changing the constant types of 'x' & 'y' to variable type. And, u will be able to compile it & run it. Hope that's clear enough. Ciao, Rajiv
The reason there isn't any default constructor provided for the const and reference type variables is you need to initialize the constant variables before the object is created and that can be done in the initilization list of the constructors and so you need to be having a custom constructor and default one cannot be used.
Thank you Rajiv and Coderzone.Noe I came to understand why user-defined constructors are necessary when there are constants.Thank you very much. I tried that one in vc++.it is giving an error about cl.exe.may vc++ is not loaded properly.After installing again I will try.
Probably its loaded but you have not choosen the correct project. I am just assuming as I dont have the idea about the error.
Here I did not choosen any project.I just opened a c/c++ source file and wrote the code there.When I compiled it creates a default workspace and project.Every time we will do like that only(for test programs).At that time it will not give any error.Now my system is changed.In this system it is showing error.I too don't know much about this.
In that case just try to compile some other very simple program. I guess if you have the country information changed the error can also come.
I tried sample Hello program.Only one cout statement.Before it compiles it is prompting an error EESWT.DLL The requested file could not be loaded.Please Re-Install Visual C++. when I click ok,it is compiled with an error message Error spawning cl.exe