Is it possible in C++ to write a function that returns a pointer to itself?
If no, suggest some other solution to make the following syntax work:
some_type f ()
{
static int cnt = 1;
std::cout << cnt++ << std::endl;
}
int main ()
{
f()()()...(); // n calls
}
This must print all the numbers from 1 to n.
You can choose to return a reference to function if needed and return
*this;Update: Of course, it is syntactically impossible for a function of type
Tto returnT*orT&Update2:
Of course, if you want one to preserve your syntax… that is
Then here’s an Idea