Does new() allocate memory for the functions of a class also?

c++, memory-management, new-operator, object

Solution

No. Functions exist in the text page and so no space is allocated for them.

Problem

``` class Animal { public: int a; double d; int f(){ return 25;} }; ``` 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()`? 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; }; ```

Original source

Related problems