objective-c – iPhone SDK Objective C是否支持函数内部的函数?

前端之家收集整理的这篇文章主要介绍了objective-c – iPhone SDK Objective C是否支持函数内部的函数?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道 javascript,例如支持函数内部的函数,如下所示:
  1. function doSomething(){
  2.  
  3. function doAnothingThing(){
  4. //this function is redefined every time doSomething() is called and only exists inside doSomething()
  5. }
  6.  
  7. //you can also stick it inside of conditions
  8.  
  9. if(yes){
  10. function doSomethingElse(){
  11. //this function only exists if yes is true
  12. }
  13. }
  14.  
  15.  
  16. }

Objective-c是否支持功能?理论范例:

  1. -(void) doSomething:(id) sender{
  2. -(void) respondToEvent: (id) sender{
  3. //theoretically? ... please?
  4. }
  5. }

奖励:“本地”功能的正确用语是什么?

解决方法

通常的术语是嵌套函数. gcc支持嵌套函数作为C的扩展(默认情况下禁用).我认为这个选项不适用于带有gcc的Objective-C(或C),即使它是使用它可能不是一个好主意(可移植性等).

gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html

猜你在找的C&C++相关文章