[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

benefit of class constructor initial list

dongfei

11/27/2008 2:10:00 PM

Hi, I have a confusion that what's the benefit of class constructor
initial list.
ex:
(1)
class A{
public: A(int i, const string& str):_i(i),_str(str){};
private:
int _i;
string _str;
};

(2)
class B{
public: B(int i, const string& str):{
_i = i;
_str = str;
};
private:
int _i;
string _str;
};

Is class A is superior to class B?
1 Answer

maverik

11/27/2008 2:15:00 PM

0

On Nov 27, 5:10 pm, dongfei <dongfei...@gmail.com> wrote:
> Hi, I have a confusion that what's the benefit of class constructor
> initial list.
> ex:
> (1)
> class A{
> public: A(int i, const string& str):_i(i),_str(str){};
> private:
> int _i;
> string _str;
>
> };
>
> (2)
> class B{
> public: B(int i, const string& str):{
> _i = i;
> _str = str;};
>
> private:
> int _i;
> string _str;
>
> };
>
> Is class A is superior to class B?

http://www.parashift.com/c++-faq-lite/ctors.htm...
Exellent explanation.