C++ examples for Class:Constructor
Initialize member variable in constructor Initialization list
#include <iostream> using namespace std; class MyNumber/* w w w . j a va 2 s . co m*/ { public: int First; MyNumber(int TheFirst) : First(TheFirst) {} }; void WriteNumber(MyNumber num) { cout << num.First << endl; } int main() { MyNumber prime = 17; WriteNumber(prime); WriteNumber(MyNumber(23)); WriteNumber(29); }