Is there a way to call a class member function automatically in the end of a scope? Apparently if the class is instantiated within the same scope, clean() can be used in the destructor of it. The question is, can we achieve that if it is instantiated before the scope? In detail:
class foo
{
public:
void do_something() {}
void clean() {}
};
int main()
{
foo c;
{
c.do_something();
// do something
// call c.clean() automatically
}
}