473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

pure virtual function: implementation?

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?

Mar 19 '06 #1
3 4553
al.c...@gmail.com 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
}
};

Mar 19 '06 #2
al*****@gmail.com 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
Mar 19 '06 #3
al*****@gmail.com 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.
Mar 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: | last post by:
I don't understand. What's the difference in practice between 2 next lines? When I *must* use first line and when second? ------------- virtual int a(int b) = 0; virtual int a(int b);...
2
by: IK | last post by:
Hello All, Please excuse me for posting this here, but I don't find any other group where I will get a proper answer. This is about clarifying the C++ part of COM. I understand that COM is a...
11
by: santosh | last post by:
Hello, I was going through the Marshal Cline's C++ FAQ-Lite. I have a doubt regarding section 33.10. Here he is declaring a pure virtual destructor in the base class. And again defining...
10
by: Martin Vorbrodt | last post by:
Example code in one of my books intrigues me: class B { public: B* Clone() const { B* p = DoClone(); assert(typeid(*p) == typeid(*this)); return p; }
21
by: sks | last post by:
Hi , could anyone explain me why definition to a pure virtual function is allowed ?
10
by: John Goche | last post by:
Hello, page 202 of Symbian OS Explained by Jo Stichbury states "All virtual functions, public, protected or private, should be exported" then page 203 states "In the rare cases where a...
3
by: keith | last post by:
Dear mentors and gurus, I noticed at the end of section 22.4 of the 'FAQ-Lite' it says "Note that it is possible to provide a definition for a pure virtual function, but this usually confuses...
10
by: Rahul | last post by:
Hi, I tried to create a abstract class by having a non-virtual member function as pure, but i got a compilation error saying "only virtual member functions can be pure"... I'm trying to think...
14
by: Jack | last post by:
Hi, I meet a question with it , I did not get clear the different betteen them, for example: #include <iostream>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.