How c++ allocate memory for class member functions?

Hi,

I am curious how c++ allocate memory for class member function.
If I have a class like:

class A
{
int n;
void function1() {......}
}

Then, I create two objects of class A; let say a1 and a2. I know that both objects will have their own memory for storing n variable. But, how's about function1?
Will a compiler allocate two blocks of memory; one for function1 of a1 and the other one for function1 of a2??

Thanks in advance.
Functions are code, not data. The fact that member functions are declared inside classes doesn't change that. Functions are not allocated, they're compiled, written to the executable, and loaded by the OS at run time into read-only memory. Only one instance of each function exists at any time, although template functions behave slightly different from the point of view of the source code.
I see. Then, there is nothing to worry about creating many functions in a class that's going to have many instances. Thanks, helios!
Topic archived. No new replies allowed.