Basic initialization
class Something
{
private:
int m_nValue;
double m_dValue;
int *m_pnValue;
public:
Something()
{
m_nValue = 0;
m_dValue = 0.0;
m_pnValue = 0;
}
};
With an initialization list
class Something
{
private:
int m_nValue;
double m_dValue;
int *m_pnValue;
public:
Something() : m_nValue(0), m_dValue(0.0), m_pnValue(0)
{
}
};
Note : This syntax can be used with const member as well. For instance, if m_nValue was a const, it would had the same effect.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.