pure virtual function: implementation?

A

al.cpwn

This is OT but since this is the c++ hangout someone might know how
this is implemented in c++ compilers. What happens when you declare a
function pure virtual in the vptr/vtable system: does the "= 0" mean
that the function pointer itself is set to 0?
 
A

Axter

This is OT but since this is the c++ hangout someone might know how
this is implemented in c++ compilers. What happens when you declare a
function pure virtual in the vptr/vtable system: does the "= 0" mean
that the function pointer itself is set to 0?

It shouldn't mean that, since you can declare implementation for a pure
virtual function on the base class itself.

class Base
{
public:
virtual int MyVirtFunct()=0
{
return 0; //Pure virtual function implementation on base class
}
};
 
K

Kiuhnm

(e-mail address removed) ha scritto:
This is OT but since this is the c++ hangout someone might know how
this is implemented in c++ compilers. What happens when you declare a
function pure virtual in the vptr/vtable system: does the "= 0" mean
that the function pointer itself is set to 0?

You cannot instantiate an abstract class then that pointer cannot be null.

Kiuhnm
 
A

AnalogFile

This is OT but since this is the c++ hangout someone might know how
this is implemented in c++ compilers. What happens when you declare a
function pure virtual in the vptr/vtable system: does the "= 0" mean
that the function pointer itself is set to 0?

If you provide an implementation for the function, it points to that.
If you do not, it points to whatever the compiler author decided to
point it at (formally: implementation defined).

A common compiler behavior is to point to an internal function that
prints a diagnostic and aborts execution.

It is not very interesting as you cannot instantiate an abstract class
anyway.

And formally ... vptr/vtable is not mandatory. If you can figure out a
different mechanism it's ok.
 

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
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top