c++ - Can we have functions inside functions? -


i mean like:

int main() {   void a() {     // code   }   a(); } 

no, c++ doesn't support that.

edit: answer old. meanwhile, c++11 has lambdas can achieve similar result – see answers below.

that said, can have local classes, , can have functions (non-static or static), can extend, albeit it's bit of kludge:

int main() // it's int, dammit! {   struct x { // struct's class     static void a()     {     }   };    x::a();    return 0; } 

however, i'd question praxis. knows (well, do, anyway :)) c++ doesn't support local functions, used not having them. not used, however, kludge. spend quite while on code make sure it's there allow local functions. not good.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -