Reputation: 1
I am curious how c++ allocate memory for class member function.
Then, I create two objects of class A; let say A and B. I know that both objects will have their own memory for storing n variable. But, how's about function one? Will a compiler allocate two blocks of memory; one for function one of A and the other one for function one of B??
class A
{
int n;
void function1() {}
}```
Upvotes: 0
Views: 91
Reputation: 2450
No, there is only one instance of the function code. The this
pointer that gets passed to that function is how it knows what object it's working with.
Upvotes: 1