confusion

if i have a constructor like Attraction(int id,string name,int typeID):id(id),name(name),typeID(typeID){} //this is with the member list initialization
do i still need Set function for each of the attributes?
Last edited on
That's up to you. Do you want to be able to set the values of those attributes after construction, or not?
but using constructor also can set values ?
But if you want to modify only typeID. You got to have a set function for typeID.
but using constructor also can set values ?

Correct. Why wouldn't it be able to set values?
if got constructor with member initialization ,why we still need a set values for the class?
if got constructor with member initialization ,why we still need a set values for the class?


To perhaps set the value whenever you want? Values change you know.
Last edited on
if got constructor with member initialization ,why we still need a set values for the class?

Think about it:

When can we use a constructor to set the state of an object?

When can we use a "set" method to set the state of an object?

Hopefully you should be able to understand why the two things provide different, complementary ways to set the state of an object.
Set is for changing the values of attributes when needed
Right. So hopefully you can see the difference between that and a constructor?
yes,is it my ram problem? i loaded very long sometimes,i using windows 10
mike9407 wrote:
yes,is it my ram problem? i loaded very long sometimes,i using windows 10

Um... what? What does that have to do with constructors and setters?
Last edited on
Refer to my another topic ,not this topic
It's better if you stick to the right topic in the right thread. Otherwise, you just confuse people.
@MikeyBoy Maybe that has been his plan all along, considering the title.
Topic archived. No new replies allowed.