dynamic types,

V

vsgdp

Does it make sense to talk about dynamic/static types with pointers in an
inheritance chain without virtual functions. You can still upcast/downcast.
Also, is it safe to say the static type is the pointer type you specify at
compile time, and the dynamic type is the type actualy pointed to---they may
be the same in the case A* a = new A();
 
A

Alf P. Steinbach

* vsgdp:
Does it make sense to talk about dynamic/static types with pointers in an
inheritance chain without virtual functions.
Yes.


Also, is it safe to say the static type is the pointer type you specify at
compile time, and the dynamic type is the type actualy pointed to---they may
be the same in the case A* a = new A();

In general it's not safe to discuss terminology.
 
A

Andrew Koenig

Does it make sense to talk about dynamic/static types with pointers in an
inheritance chain without virtual functions. You can still
upcast/downcast.

Yes it does. Consider:

struct A { };
struct B : A { };

A* p = new B;
delete p; // undefined behavior

The statement "delete p;" has undefined behavior because the static type of
*p differs from its dynamic type and struct A doesn't have a virtual
destructor. If it didn't make sense for me to talk about static and dynamic
types in this context, how would I explain why "delete p;" has undefined
behavior?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top