how to get type information in C++

Hi Masters:
i have a question about how does compiler know the type information.
e.g.
class A{};
A* p;

when we need to dereference p, or such like ++p, the pointer arithmetic, how does compiler know how much amount to move ahead? or, how does the compiler to get the type information?

my naive understanding is:
p stores a machine word, and that's all p has.
form only p's content(a machine word), compiler can not deduce what is p.
So how does compiler knows what type is p?
is there a table or something?
thanks.
The compiler knows everything since it sees your source code.

It obviously can see that p is a pointer-to-A since it parsed the declaration

A* p;

What the compiler 'sees'and what the compiler 'generates' are very different and I suspect you are confusing the two.

The compiler sees the type information. The source code is required to include it and the compiler's job is to keep a note of every type so that it can allocate the right amount of space and do correct pointer arithmetic.
Topic archived. No new replies allowed.