is it correct to do this? set x=4 in a default constructor? want'ed to set the initial value of a variable in class that gets created by a default constructor.Code:class base{ private: int x; public: base(){ x=4; } };
is it correct to do this? set x=4 in a default constructor? want'ed to set the initial value of a variable in class that gets created by a default constructor.Code:class base{ private: int x; public: base(){ x=4; } };
Your question is, is it correct to properly initialize an object? Well... yes?
The only thing that isn't quite right is that you should initialize members like this:
Instead of what you have there (i.e., use the initializer list)Code:base::base() : x( 4 ) { }
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}