473,394 Members | 1,703 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,394 software developers and data experts.

virtual inheritence: what does it mean?

Hi all,
I recently saw a piece of code that looks like:

class one{public: one(){} };
class two : public virtual one{public: two(){} };
class three : virtual public one{public: three(){} };

My questions:

1. What does it mean to have a virtual inheritenec? When do you want
that? What affect does it have on class two and three?

2. It seems like you can say "public virtual" or "virtual public".
Does order matter?

Thanks!
Jul 22 '05 #1
2 2119
This helps in multiple inheritance. If class four :public two, three ..
then class four will have only one instance of class one variables/methods,
no ambiguity.
check out C++ FAQs
"pembed2003" <pe********@yahoo.com> wrote in message
news:db**************************@posting.google.c om...
Hi all,
I recently saw a piece of code that looks like:

class one{public: one(){} };
class two : public virtual one{public: two(){} };
class three : virtual public one{public: three(){} };

My questions:

1. What does it mean to have a virtual inheritenec? When do you want
that? What affect does it have on class two and three?

2. It seems like you can say "public virtual" or "virtual public".
Does order matter?

Thanks!

Jul 22 '05 #2

"pembed2003" <pe********@yahoo.com> wrote in message
news:db**************************@posting.google.c om...
Hi all,
I recently saw a piece of code that looks like:

class one{public: one(){} };
class two : public virtual one{public: two(){} };
class three : virtual public one{public: three(){} };

My questions:

1. What does it mean to have a virtual inheritenec? When do you want
that? What affect does it have on class two and three?

2. It seems like you can say "public virtual" or "virtual public".
Does order matter?

Thanks!


In short it helps to avoid duplicate base objects in a so called "diamond
shaped" inheritance pattern. For a more elaborate answer you should check
out the FAQ where it is covered in all detail.

http://www.parashift.com/c++-faq-lit....html#faq-25.9

HTH
Chris
Jul 22 '05 #3

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

Similar topics

2
by: dcipher | last post by:
I'm in the process of rewritting my graphics library to be purely OO using C++. The following is a section of my heirarchy of classes: PImage // defines all basic graphics routines as...
5
by: alex goldman | last post by:
When compiling this code with g++ -Wall -pedantic -ansi -c program.cpp # this is GCC-3.3.4 ###################################### #include <vector> class b { public: virtual void f() = 0;...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
14
by: Bruno van Dooren | last post by:
Hi all, i am having a problems with inheritance. consider the following: class A { public: A(int i){;} };
5
by: Alok | last post by:
hii Would somebody clear my doubts on following qustions . What are virtual constructors and virtual destructors ? Why can't we have virtual constructors ? What are demerits of inheritence in...
2
by: Heinz Ketchup | last post by:
Hello, I'm looking to bounce ideas off of anyone, since mainly the idea of using Multiple Virtual Inheritance seems rather nutty. I chalk it up to my lack of C++ Experience. Here is my...
7
by: BeautifulMind | last post by:
In case of inheritence the order of execution of constructors is in the order of derivation and order of destructor execution is in reverse order of derivation. Is this case also true in case...
7
by: v4vijayakumar | last post by:
Is it possible to implement member object's virtual functions, in the containing class? If not, is it possible to simulate this behavior? ex: class test { protected: virtual void fun() = 0;...
3
by: Juha Nieminen | last post by:
It occurred to me while developing an application: What happens if two (completely independent) base classes have the exact same virtual function, and then a derived class is derived from both,...
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: 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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
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...

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.