By standard C++ dose not support use of nested function, some compiler allows it but that depends on compiler being used. So there is one work around by using you can achieve nested function in C++.
By using local class and overloading function operator we can simulate nested function. Following is my sample code to achieve nested function.
void foo() { class DoMyWork { public: int operator() (int args) { qDebug() << "Parameter passed:" << args; return args + 5; } } doMyWork;//creating instance of DoMyWork
//calling simulated nested function int retVal = doMyWork(5); qDebug() << "Returned value:" << retVal; }So that was all, hope this helps.
No comments:
Post a Comment