C++ examples for Class:Constructor
Set default value in constructor
#include <iostream> using namespace std; class MyClass//from w w w . j a v a 2s . co m { private: int secret; public: MyClass() { secret = 150; } int &GetValue() { return secret; } void Write() { cout << secret << endl; } }; int main() { MyClass inst; inst.Write(); int &pry = inst.GetValue(); pry = 30; inst.Write(); return 0; }