My goal is to allow chaining of methods such as:
class Foo;
Foo f;
f.setX(12).setY(90);
Is it possible for Foo‘s methods to return a pointer to their instance, allowing such chaining?
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.
For that specific syntax you’d have to return a reference
P.S. Or you can return a copy (
Fooinstead ofFoo&). There’s no way to say what you need without more details, but judging by the function name (Set...) you used in your example you probably need a reference return type.