Constructor Question

What is the point of the portion after the single ":"? If I were to put "Person::Person(string firstname, string lastname, int arbitraryNumber)", would I need the second part?

1
2
  Person::Person(string first, string last, int arbitrary)
       : firstname(first), lastname(last), arbitraryNumber(arbitrary)
Member initializer lists. See http://en.cppreference.com/w/cpp/language/initializer_list

The point is the ability to pass parameters to the constructors of the members of the class.

Yes, you want it.
Last edited on
Can I name them the same thing? For instance:

Person::Person(string first, string last, int arbitrary)
: first(first), last(last), arbitrary(arbitrary)
Thank you.

The links you provided me have a lot of good information that was relevant to my question.
Topic archived. No new replies allowed.