Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning the class pointer through function

How can i return the pointer of the Foo class using its functions. The reason why i ask is because i want to make this code work

Class fo
fo.MakeA(34.5777).MakeY(73.8843);

Thank you very much in advance

like image 764
pondigi Avatar asked Feb 25 '23 20:02

pondigi


1 Answers

Assuming that you need a reference return type;

class foo {
public:
  foo& MakeA(float a) {
    // MakeA code logic here...
    return *this;
  } 
  foo& MakeB(float b) {
    // MakeA code logic here...
    return *this;
  } 
}

Otherwise, you can just return a copy (foo instead of foo&).

like image 143
Carlos Avatar answered Mar 02 '23 00:03

Carlos