Is it good to have all the setter functions return a reference to the object in c++?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a usable enough pattern if there’s a lot of things that need to be set on an object.
This pattern replaces a constructor that takes three ints:
It’s useful if you have a number of values that don’t always need to be set.
For reference, a more complete example of this sort of technique is refered to as the ‘Named Parameter Idiom‘ in the C++ FAQ Lite.
Of course, if you’re using this for named parameters, you might want to take a look at boost::parameter. Or you might not…