Results 1 to 6 of 6

Thread: Confused with Virtual inheritance

  1. #1
    Join Date
    Dec 2009
    Posts
    68

    Confused with Virtual inheritance

    Hello guys,

    I am IT student and currently studying OOPs concept of java. I am little bit aware about the inheritance concept, and specially about the multiple inheritance. But I am not getting what is 'Virtual inheritance' and it's use. I have go through many books for this but nothing was helpful. I wonder if you provide information something about the 'Virtual inheritance'. It will be be great if you explain it with suitable example.

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

    Re: Confused with Virtual inheritance

    Hi,

    Virtual Inheritance is a mechanism to compensate the disadvantages repeated inheritance. The legacy is in virtual mode if the keyword virtual is present in the modifier inheritance. The following figure shows a case of repeated inheritance:
    • The attributes of class A are present in double copy in class D, once because of the legacy from B, again because of the legacy from C
    • Manufacturers B and C are supposed to call all both the manufacturer of A which does not fail to pose a major problems.

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

    Re: Confused with Virtual inheritance

    Following is the example of implementation of Virtual inheritance:
    Code:
    class Has
    {
      Public:
        A ()
        {
          court << "Manufacturer A" <<endl;
        }
      private:
        int a;
    };
    
    class B: virtual Public  A?
    {
      Public:
           B (): A ()
        {
          court << "B constructor" <<endl;
        };
      private:
        int b;
    );
    
    class C: virtual Public A?
    {
      Public:
           C (): A ()
        {
          court << "constructor C" <<endl;
        };
      private:
        int c;
    };
    
    class D: virtual Public Has, Public B Public C?
    {
      Public:
        D () A ()
              B ()
              C ()
    
        {
          court << "constructor D" <<endl;
        };
      private:
        int d;
    };

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Confused with Virtual inheritance

    Suppose you provide a library including all classes derive from a common ancestor. It is necessary use of virtual inheritance so that your client can of safe multiple inheritance. First, you must decide if your classes have a chance to be derived by your client and if so, can he desire to associate with another class of your library? if the answer is yes, then you must provision of virtual inheritance in all other cases, use the legacy of "normal".

  5. #5
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Confused with Virtual inheritance

    HI friend,

    The virtual inheritance adds considerably table management of virtual methods and attributes. The order of modifiers and virtual audience in a Virtual heritage is irrelevant. For example you have class 'A', and if constructor of A is explicitly named in the D ensuring the proper initialization of inherited attributes of A. Consequently, calls the constructor of A from those of B and C will not be executed.

  6. #6
    Join Date
    May 2008
    Posts
    2,012

    Re: Confused with Virtual inheritance

    Hi,

    Virtual inheritance can be used within multiple inheritance. Suppose if a class 'V' has a direct parent class 'T', then it can inherit it indirectly using several inheritance lines. In short the Virtual Inheritance is nothing but the process for to compensate the demerits of the repeated inheritance. The idea of the Virtual inheritance is always hold he virtual content , but the similar order as they have stored.

Similar Threads

  1. Replies: 3
    Last Post: 08-01-2011, 06:32 AM
  2. What is an Inheritance in C#?
    By - Empty Shell - in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 07:03 AM
  3. Confused about virtual methods
    By Bottlenecked in forum Software Development
    Replies: 5
    Last Post: 06-02-2010, 12:36 PM
  4. Polymorphism VS Inheritance
    By Taylor D in forum Software Development
    Replies: 5
    Last Post: 22-01-2010, 10:12 AM
  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,718,175,733.16108 seconds with 16 queries