Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > pure virtual function: implementation?

Reply
Thread Tools

pure virtual function: implementation?

 
 
al.cpwn@gmail.com
Guest
Posts: n/a
 
      03-19-2006
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?

 
Reply With Quote
 
 
 
 
Axter
Guest
Posts: n/a
 
      03-19-2006
(E-Mail Removed) wrote:
> 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
}
};

 
Reply With Quote
 
 
 
 
Kiuhnm
Guest
Posts: n/a
 
      03-19-2006
http://www.velocityreviews.com/forums/(E-Mail 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
 
Reply With Quote
 
AnalogFile
Guest
Posts: n/a
 
      03-19-2006
(E-Mail Removed) wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need clarification for virtual method and pure virtual function a C++ 7 06-28-2007 12:38 PM
virtual vs pure virtual member function sam_cit@yahoo.co.in C++ 7 05-02-2007 10:00 AM
private virtual functions and pure virtual functions with bodies John Goche C++ 10 12-08-2006 04:00 PM
Pure functions still pure after definition Todd Aspeotis C++ 3 05-30-2005 03:53 AM
virtual function and pure virtual function in the implementation of COM IK C++ 2 07-23-2004 02:55 PM



Advertisments