加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C类范围

发布时间:2020-12-16 09:26:08 所属栏目:百科 来源:网络整理
导读:我是从Objective C来到C并遇到问题…… 这有效: – function1(char *filePath) { Box box(filePath); // construct/create a box using filePath // can use box in this function and destructor is called when function exits} 但是我需要这样的东西,其
我是从Objective C来到C并遇到问题……
这有效: –

function1(char *filePath) {

    Box box(filePath); // construct/create a box using filePath

    // can use box in this function and destructor is called when function exits

}

但是我需要这样的东西,其中function1和function2是异步调用的.

Box *boxPool[25]; // a pool of 25 box pointers

function1(int item,char *filePath) {

    boxPool[item](filePath); // construct/create a box,store a pointer in boxPool that is retained on exit

}

function2(int item) {

    // use the box from boxPool[item] and then destruct/release it on exit

}

解决方法

也许:

void function1(int item,char *filePath) {

    boxPool[item] = new Box(filePath);

}

void function2(int item) {

  //use boxPool[item]

  delete boxPool[item];
  boxPool[item] = NULL;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读