Results 1 to 6 of 6

Thread: Does anyone know about virtual constructors and destructors?

  1. #1
    Join Date
    Dec 2009
    Posts
    38

    Does anyone know about virtual constructors and destructors?

    Hello friend,

    I have enough knowledge about the constructor and destructor from the java programming. But the 'virtual constructors and destructors' seems to be very difficult to understand. Constructor comprises same name as per the class name, but what about the 'virtual constructors'? If you posses knowledge about the 'virtual constructors and destructors' then please let me aware about that. I am waiting for your reply.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Does anyone know about virtual constructors and destructors?

    Unlike Java, C + + offers no mechanism to prohibit inheritance (final keyword in Java). You must therefore check, before inheriting, the base class does have a virtual destructor. No need to declare a virtual destructor if it is not a base class or subclass. If a class has a virtual constructors (this includes the destroyer), then additional data are added to the class. These data allow the program running to know what methods must be used in case of inheritance.

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: Does anyone know about virtual constructors and destructors?

    Refer following details about the 'virtual constructors':
    • In virtual constructors the definition of a class is not required when not needed.
    • It has the same name as the class has.
    • Virtual constructor can have arguments
    • virtual constructor has no return type.

  4. #4
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Does anyone know about virtual constructors and destructors?

    The virtual destructor of an object created is called statically implicitly when the program leaves the scope in which the object are created. If an object with a virtual destructor is destroyed by using delete operator to a super class pointer, then super class destructor function is called on the object. The destructor is a function whose definition is very similar to that the manufacturer, except that the name of the destructor is preceded by a tilde (~) and he has no argument.

  5. #5
    Join Date
    May 2008
    Posts
    2,389

    Re: Does anyone know about virtual constructors and destructors?

    The virtual constructors are related to the code associated with the class of the object, rather than the class pointer. A class has a virtual constructors if it has a explicitly defined destructor or if it has a member of base class that has a destructive. destructor can not be overloaded, or have a default value for its arguments, since it simply has not. The virtual destructive is called differently depending on whether the object to which it belongs has been created statically or dynamically.

  6. #6
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Does anyone know about virtual constructors and destructors?

    Hi friend,

    If you create polymorphic classes that is inheriting from other classes, you must declare your virtual destructors unless you want to have some strange behavior and memory leaks. For to declare virtual destructors, Just add the keyword virtual before the name of the destroyer of the base class and all its derived classes. The destroyers were generally much less need to be defined as manufacturers, so this is the default destructor is called if necessary.

Similar Threads

  1. Do Virtual Destructors exist in C++ ?
    By Satchel in forum Operating Systems
    Replies: 6
    Last Post: 20-01-2011, 10:25 PM
  2. what are constructors in C++?
    By Asis in forum Software Development
    Replies: 4
    Last Post: 29-12-2010, 08:38 AM
  3. Constructors and Destructors in PHP
    By garfield1 in forum Software Development
    Replies: 4
    Last Post: 02-03-2010, 11:01 PM
  4. What are the Constructors and Destructors?
    By RupaliP in forum Software Development
    Replies: 4
    Last Post: 27-02-2009, 07:03 PM
  5. migrate Hyper-V virtual machine to virtual server/virtual PC 2007
    By Larry Scott in forum Windows Server Help
    Replies: 1
    Last Post: 18-03-2008, 03:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,050,334.74945 seconds with 16 queries