I want to know how does class object (not instances, but exactly classes) store in memory?
class A {
public:
int a;
virtual void f();
virtual ~A();
};
class B : public A {
public:
int b;
void f() final override;
};
I know, that usually (not strongly described by standard) in case of this inheritance (B derived from A) we have:
memory: ....AB...
where AB is a class object of B (if I understand it correctly). If we go deeper (tried with clang and gcc), we can see something like (again, not strongly described in standard):
A
vtptr*
int a
B
vtptr*
int b
Okay, now we see where do the a
and b
properties store. And we also see the pointer to virtual method table. But where does vtptr*
(virtual method table) actually store? Why not near with the classes? Or it does?
Also, here is another question: I was able to change virtual method tables by changing the pointers (simple logic). Can I also change a pointer to it's methods safely?
P.S. In your questions you may answer for gcc and clang. P.P.S. If I am wrong somewhere please point it too in your answers.