Returning a class pointer through a function

How can I return a pointer to the class Foo using its functions. The reason I'm asking is because I want this code to work

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

Thank you in advance

+4
source share
2 answers

Assuming 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 simply return a copy ( foo instead of foo& ).

+6
source

You want to use an indexer for your class.

Make the return type for (MakeA, MakeY) the same data type as the class (with ref &).

and at the end of each method put

 return *this; 
+2
source

All Articles