GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Tech FAQs  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 218 of 255    Print  
why virtual constructors are not there in C++ while we have vitual destructors?

  
Total Answers and Comments: 1 Last Update: May 04, 2006     Asked by: Sidharth sharma 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
May 04, 2006 07:26:08   #1  
Sandeep Godbole        

RE: why virtual constructors are not there in C++ whil...

virtual destructor become meaningful when ur deleting an object of derived class associated with the pointer of base class. For ex. if A is base and B is derived and if we write expr. A *pa = new B and delete pa, we observe that destructor of derived class is not called. Compiler recognize pa as pointer of base and bothers to place call only to destructor of base. Now that could result into some serious problem. For ex. if class B holds some pointer to which we have dynamically allocated some space. Now its a standard practice to delete such allocations in destructor. Now if the destructor itself is not called in that case it would lead to memory leackage. Declaring base class destructor as virtual ensures call is placed to derived. Hence we need to have virtual destructor. There is no need to have virtual constructor as because when u write A *pa = new B a call to both i.e. constructor of A as well as B is placed by compiler. There is no call missed out. Hence no need of virtual constructor. However a concept called virtual constructor still exist, not in the form as applying virtual to constructor but something differently. More on that on request.


 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : When classes are inherited, we need to make the base class destructor virtual – to make sure when the object is destroyed, all the derived class destructors also called. Otherwise the derived class destructors are not called because the there is compile ...

Latest Answer :     Hi            In My opinion there is no such concept In C++           But some  says Can anyone tell mehow is it possible???  ...

Latest Answer : In C you would use an array of pointer-to-functions and call the functions by using the array index. ...

Latest Answer : Also increases memory consumption since a virtual function address table has to be maintained in RAM ...

Latest Answer : Virtual Base Class: Used in context of multiple inheritance in C++. If you plan to derive two classes from a class, and further derive one class from the two classes in the second level, you need to declare the uppermost base class as 'virtual' in the ...

Latest Answer : To achieve runtime polymorphism.For a virtual function which is defined in both the base and derived classes, the decision of which implementation to call is taken at runtime depending on the type of object, and NOT depending on the declaration type of ...

Latest Answer : A pure virtual function is a function declaration with the keyword 'virtual' prefixed to it and definition equated to 0. In C++ declaring a pure virtual function makes the class abstract.e.g. virtual void f() = 0; ...

Latest Answer : Virtual base class is a term used in C++ multiple inheritance.Assume the following -- base class P. Two classes A and B derive from P. A third class C derives from both A and B.P has a protected variable pvar. A class C method accesses this variable. ...

Latest Answer : Virtual destructor has the same concept as a virtual function.To decide at runtime, depending on the type of object, whether to call derived class destructor or base class destructor. Useful in situations where base class pointer is used to create a derived ...

Latest Answer : At the time of constructing the object the type is given as input (B *ptr = new D) here it is clearly known that D's constructor is to be called. However while destroying, delete ptr; does not make it clear whether to call B's destructor (looking at the ...


 Sponsored Links

 
Related Articles

OOPS Tutorials

Object oriented programming OOP is a computer science term used to characterize a programming language that began development in the 1960’ s The term object oriented programming’ was originally coined by Xerox PARC to designate a computer application that describes the methodol
 

Online Virtual Business Network

How to begin an Online Virtual Business Network What is Virtual Business Network Business and commerce right from the ancient days depended a lot on the physical representation of the business and the physical identity of the customers and other collaborators Most of the business dealings were done
 

Agility in Virtual Business Networks

Agility in Virtual Business Networks Agility means responding to rapid changes and continuous change management With the rapid economic changes and unexpected market behavior the virtual business networks have to adapt themselves to be able to respond in a timely and fast manner Therefore agility pr
 

Creating Virtual Business Network

Requirements of Virtual Business Network The sudden expansion of electronic commerce has resulted in many changes in the way business is done globally The virtual business network is the buzz word among the business communities internet community and freelance work seekers Traditional business strat
 

Business Network Virtual Communication Tools

Business Network Virtual Communication Tools Since ages the Business community heavily relied on face to face communication for building Business relationships Face to face communications formed the basis for trust in a relationship An individual’ s appearance or the physical appearance of
 

Virtual Business Networks

Virtual Business Networks Classification of Virtual Business Networks Virtual Business Network is the most discussed topic among the Business Communities nowadays The basic definition of a Virtual Business Network means a group of small Businesses joining together to collaborate and co operate to ac
 

Collaboration in Virtual Business Networks

Collaboration in Virtual Business Networks Most common businesses are small and majority of them are home based businesses The small businesses have different common fields ranging from the traditional consumer business to technological trading Mostly these small businesses have been responsible for
 

C++ Pure Virtual Function and Base Class

C Pure Virtual Function and Virtual Base Class In this C tutorial you will learn about pure virtual function declaration of pure virtual function and virtual base class virtual base class and how to implement a virtual base class explained with examples mosgoogle center What is Pure Virtual Function
 

C++ Virtual Functions

C Virtual Functions What are Virtual Functions Virtual as the name implies is something that exists in effect but not in reality The concept of virtual function is the same as a function but it does not really exist although it appears in needed places in a program The object oriented programming la
 

Virtualization Virtual Servers and Virtual Storage

Virtualization Virtual Servers and Virtual Storage Virtualization is one of the major software trends of 2007 This type of software allows multiple OSs operating systems to run side by side from a single server Servers are computer systems that provide services to other systems or clients All major
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape