Tuesday, September 13, 2011

Constructor with initializer list

example:
Constructor with initializer list

#include <iostream>

using namespace std;

class MyClass{
public:
MyClass();
~MyClass();
private:
string myName;
string myNote;
};

//Constructor with initializer list
MyClass::MyClass()
:myName("initName"), myNote("initNote")
{
cout << "MyClass Constructor: " << myName << endl;

}

MyClass::~MyClass(){
cout << "MyClass Destructor: " << myName << endl;
}

int main()
{
MyClass myClass1;
return 0;
}



No comments:

Post a Comment