473,508 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

what is the need that we use pure virtual insted virtual funcatio

1 New Member
what is the reason that we use pure virtual function instead of virtual function. what is uniquness pure virtual function we use
Feb 14 '14 #1
1 866
weaknessforcats
9,208 Recognized Expert Moderator Expert
Virtual functions are only used when you implement polymorphism.

C++ polymorphism is used by creating derived class objects and using them through a base class pointer. The virtual keyword tells the compiler that if there is a choice between calling the base class method or calling the derived class method, it is the derived class method that is to be called.

When doing things this way it is the base class that has the interface to the hierarchy. Derived classes are to implement methods declared in the base class. However, if the derived class chooses to not implement a method in the base class, then the base class must implement that method in order for things to compile.

The pure virtual function is just a virtual function like any other virtual function except it cannot be called by an object of its class. That is, if the pure virtual function is declared in the base class, you cannot use a base class object to call it. This forces the derived class to implement the method or things won't compile.

To make sure you don't even try to call the pure virtual function from its class, the compiler will not let you create an object of that class.
Feb 14 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1967
by: Jim Fischer | last post by:
Paragraph 10.3/2 in the C++ standard has the following code example: <quote> struct A { virtual void f(); }; struct B : virtual A { virtual void f(); };
4
2492
by: garyolsen | last post by:
class base{ public: void NonVirtualMethod(int a); virtual void VirtualMethod(int a); }; class derived{ public: void NonVirtualMethod(int a, char c); void VirtualMethod(int a, char c);
2
1194
by: Xiangliang Meng | last post by:
Hi, all. What will happen if a virtual function is declared to be virtual again in a derived class? Any harm? Best Regards, Xiangliang Meng
9
1894
by: jlopes | last post by:
There seems to bet no diff between a vitual method and an inheirited method. class A_Base { public: virtual void filter(){ /* some code */ } }; class D_of_A_Base : public A_Base {
1
1526
by: sachin16 | last post by:
Hey guys, can anyone tell me what are the significances of virtual functions in C++?
2
1523
by: suneel | last post by:
hi all I am new to the C++ please help me what is the use of virtual constructors in c++, and when we can use these virtual constructors.
0
1791
by: akshaycjoshi | last post by:
I am reading a book which says Even though unboxed value types don't have a type object pointer, you can still call virtual methods (such as Equals, GetHashCode, or ToString) inherited or...
4
2062
Mahesh Baria
by: Mahesh Baria | last post by:
what is diffrence between virtual and pure virtual?
3
3016
by: umair ali | last post by:
is pure virtual function has more memory than virtual function?????
0
7231
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
7336
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,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.