Wednesday, March 31, 2010

Member Initialization List

Do you know "Member Initialization List"?

For example.

class CMyTestClassA
{
public:
int width;
int height;

CMyTestClassA(int a, int b) : width(a), height(b)
{
}

int getArea(void)
{
return (width*height);
}
};

It is same as belowing,

class CMyTestClassB
{
public:
int width;
int height;

CMyTestClassB(int a, int b)
{
width = a;
height = b;
}

int getArea(void)
{
return (width*height);
}
};

From the document, 1st class is faster than send class.

No comments: