new()是否也为类的功能分配内存? [英] Does new() allocate memory for the functions of a class also?
本文介绍了new()是否也为类的功能分配内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Animal
{
public:
int a;
double d;
int f(){ return 25;}
};
假设上面的代码,我尝试通过说new Animal()
来初始化一个对象,这个new()
是否也为函数f()
分配了内存?
Suppose for the code above, I try to initialize an object, by saying new Animal()
, does this new()
also allocate memory for the function f()
?
换句话说,如果我改为使用此类并执行了new Animal()
吗?:
In other words, what is the difference in memory allocation terms if I had this class instead and did a new Animal()
? :
class Animal
{
public:
int a;
double d;
};
推荐答案
否.功能存在于文本页面中,因此没有为它们分配空间.
No. Functions exist in the text page and so no space is allocated for them.
这篇关于new()是否也为类的功能分配内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文