Re: benefit of class constructor initial list

Discussion in 'C++' started by maverik, Nov 27, 2008.

  1. maverik

    maverik Guest

    On Nov 27, 5:10 pm, dongfei <> 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.html#faq-10.6
    Exellent explanation.
    maverik, Nov 27, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ian Pilcher

    Class.cast(Object) - what benefit?

    Ian Pilcher, Aug 20, 2005, in forum: Java
    Replies:
    16
    Views:
    21,333
    Ian Pilcher
    Aug 23, 2005
  2. mrstephengross
    Replies:
    5
    Views:
    587
    Larry I Smith
    May 18, 2005
  3. DaTurk
    Replies:
    6
    Views:
    348
    Ian Collins
    Jan 25, 2007
  4. ali
    Replies:
    4
    Views:
    561
    David Harmon
    Mar 5, 2007
  5. Generic Usenet Account
    Replies:
    10
    Views:
    2,205
Loading...

Share This Page