Cocos2d-x??????C++??????
???????????? ???????[ 2015/1/29 14:36:16 ] ????????C++ ??????? ??????
?????????????н???C++?????C++????????????????в???????????????????Cocos2d-x?е??????????????б????????ЩC++???????????
????C++?????????????????????????????????????????????????????????????????????C++??????????????÷?????
??????????????
??????????????????????裺?????????????????棬??????????ù????????????檔???????ж???????????????????????????????????????????????????£?
????????????????????????????????????????У?Ч????????????????????????????????????????????????????????????????????????????????????к????????????????????洢????????????????????????н??????Щ?洢????????????????
?????????????????????????????????????????????????費???????????????????????? ????????е??????malloc??new??????????????棬???????????????????free??delete?????檔???????????????????????????÷??????????????
?????????洢??????????????????????????????????????????????????????????á??????????????????????????
?????????????
?????????????????????????????????????????????????????????malloc??new??????棬???free??delete?????檔????malloc??free??????new??delete??????
????1??malloc??free???
????malloc??free??C/C++????????????????????C????á????malloc??????????????????????ù????????????檔???free??????????????????????????????????檔
???????malloc??free??????????????????????????£?
#include <iostream>
using namespace std;
class MyObject
{
public :
MyObject(){??
cout << "call constructor." << endl;
}
~MyObject(){ ??
cout << "call destructor." << endl;
}
void initialize(){ ??
cout << "call initialization." << endl;
}
void destroy(){??
cout << "call destroy." << endl;
}
};
int main(){
MyObject *obj = (MyObject *)malloc(sizeof(MyObject)); // ???????? ??
obj->initialize();??
//TODO
obj->destroy();??
free(obj);??
obj = NULL;
return 0;
}
??????????????????????MyObject?????е???д?????????????????????д???????????????????????д??????????????????void initialize()?????malloc??????????????ù??????????????ú?????????????????д????????????????void destroy()?????free???????????????????ú?????????????Щ?????
???????~?????????MyObject????????????е???д???MyObject *obj = (MyObject *)malloc(sizeof(MyObject))?????malloc??????????棬???ú??????????????????????malloc???????????void*?????C++?????void*???????????????????????????????????????????????????????????????д?????????????
????????д???free(obj)?????obj??????檔????????????????????????д???obj->destroy()??????????????????????????????Щ?????????????????????????????????????????????~MyObject()????е??á?
??????н?????????£?
????call initialization.
????call destroy.
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11