首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

why and when should I use operator 'new'?解决办法

2012-03-13 
why and when should I use operator new?ItisinterestingwhenIfoundIneverusenewbutallclassesworkwell

why and when should I use operator 'new'?
It   is   interesting   when   I   found   I   never   use   'new '   but   all   classes   work   well.
So,   here   comes   the   question,   could   anyone   tell   me   why   and   when   I   should   use   operator   'new '?

[解决办法]
就像你定义了int a变量,你不需要用new来申请空间一样,编译器为你分配了空间.但是当你定义int *a的时候,你需要用new申请空间.
Class A
{
}
A a; //不用要用new,编译器自动在栈中为A分配了空间.
A *a;
a = new A;//手动在堆中申请空间

热点排行