In Java you can simply return this to get the current object. How do you do this in C++?
Java:
class MyClass {
MyClass example() {
return this;
}
}
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.
Well, first off, you can’t return anything from a
void-returning function.There are three ways to return something which provides access to the current object: by pointer, by reference, and by value.
As indicated, each of the three ways returns the current object in slightly different form. Which one you use depends upon which form you need.