Just like the other answers, I see two differences:
First optional parameters:
Base(int nValue=0)
versus
Base(int nValue)
The first one takes an
optional first parameter in the constructor. If you don't use a parameter in your constructor, it'll be 0. The second one must take a value (though another issue in that second constructor is that you over-write that input with a 0, leaving that input unused.
Second, initializer list:
1 2
|
Base(int nValue=0)
: m_nValue(nValue)
|
The code above says that m_nValue is created and initialized to nValue.
1 2 3
|
Base(int nValue){
m_nValue=nValue;
}
|
The code above says that m_nValue is created, and is later set to nValue.
For primative types, this isn't very interesting, but it can be very interesting otherwise for these reasons:
1. You can specify a non-default constructor for a member in your initializer list.
2. You can skip a potentially lengthy default constructor for a member in your initializer list.
3. You can initialize a
const
member in your initializer list.