class vehicle{ ... }; class motorVehicle: virtual public vehicle{ ... }; class twoWheels: virtual public vehicle{ ... }; class motorcycle: public motorVehicle, public twoWheels, virtual vehicle{//(1) .... };   (1) Why does class motorcycle has to inherit class vehicle, when it is already contained in classes motorVehicle and twoWheels? In the explanation from the book it is written that class motorcycle has to inherit class vehicle in order to make sure that the constructor of the base class (vehicle) will be called. If this explanation is correct, I don't understand why it says "virtual vehicle"? What type of inheritance is this?
78578
I want to know what a "virtual base class" is and what it means.  Let me show an example:  class Foo { public:     void DoSomething() { /* ... */ } };  class Bar : public virtual Foo { public:     void DoSpecific() { /* ... */ } };
25912
Is it possible for a generic interface's type to be based on a specific parent class?  For example:  public interface IGenericFace&lt;T : BaseClass&gt; { }   Obviously the above code doesn't work but if it did, what I'm trying to tell the compiler is that T must be a sub-class of BaseClass.  Can that be done, are there plans for it, etc.?  I think it would be useful in terms of a specific project, making sure a generic interface/class isn't used with unintended type(s) at compile time.  Or also to sort of self-document: show what kind of type is intended.
87337
I've got a (poorly written) base class that I want to wrap in a proxy object. The base class resembles the following:  public class BaseClass : SomeOtherBase  {    public BaseClass() {}     public BaseClass(int someValue) {}     //...more code, not important here }   and, my proxy resembles:  public BaseClassProxy : BaseClass {   public BaseClassProxy(bool fakeOut){} }   Without the "fakeOut" constructor, the base constructor is expected to be called. However, with it, I expected it to not be called. Either way, I either need a way to not call any base class constructors, or some other way to effectively proxy this (evil) class.
15868
Why does this code:  class A {     public:          explicit A(int x) {} };  class B: public A { };  int main(void) {     B *b = new B(5);     delete b; }   Result in these errors:   main.cpp: In function ‘int main()’: main.cpp:13: error: no matching function for call to ‘B::B(int)’ main.cpp:8: note: candidates are: B::B() main.cpp:8: note:                 B::B(const B&)   Shouldn't B inherit A's constructor?  (this is using gcc)
106322
(I asked a similar question, but it had more questions inside it and I feel it wasn't clear enough, so I'm opening a new one).  Until recently I implemented all my games using an inheritance hierarchy. Those were simple games.  For example:            Entity           /    \       Movable  Static       /  \        /  \     Orc  Mage   Tree  Wall   This worked for simple games.  However recently I read about 'entity component systems'. Using this approach, a class doesn't inherit from another class in order to receive functionality. Instead it is composed with it, which allows for more flexible designs.  My question is this:  I know that each component is a class (derived from a common base class).  However, there is one thing I don't understand: In the 'component system' approach, is there one class that all entities are instances of - and the only difference between entities is the components they contain?  For example: There is a class Entity. All entities in the game are instances of this class.  The only differences between them is that they are composed with different Component objects.  For example:  Component aiComponent = new AIComponent(); Component movementComponent = new MovementComponent(); Component physicsComponent = new PhysicsComponent(); Component rangedAttackComponent = new RangedAttackComponent();  Entity orc = new Entity(); orc.addComponent(aiComponent); orc.addComponent(movementComponent); orc.addComponent(physicsComponent);  Entity shootingCastle = new Entity(); shootingCastle.addComponent(aiComponent); shootingCastle.addComponent(rangedAttackComponent); shootingCastle.addComponent(physicsComponent);   All of this as opposed to my old approach:  Orc orc1 = new Orc(); ShootingCastle castle1 = new ShootingCastle();   As you can see, both orc and shootingCastle are instances of the Entity class. But they are composed with different components.  Is this how 'entity component systems' are supposed to be? No inheritance hierarchy at all? Or is there still a basic inheritance hierarchy, but most of the logic is inside components?
57504
So that's bicycle, skateboard, scooter etc. Problem is that these also have motor powered versions, but if you just say vehicle, people will think that you mean cars or something. Also, you can't search for those powered versions collectively because what would you put in the search bar, "motor powered, human powered vehicles"? If you just use "powered vehicles" all results are cars.
5798
Is there any meaningful distinction between:  class A(object):     foo = 5   # some default value   vs.  class B(object):     def __init__(self, foo=5):         self.foo = foo   If you're creating a lot of instances, is there any difference in performance or space requirements for the two styles? When you read the code, do you consider the meaning of the two styles to be significantly different?
108429
When are objects or something else said to be "first class" in a given programming language, and why? In what do they differ from languages where they are not?  EDIT. When one says "everything is an object" (like in Python), does he indeed mean that "everything is first-class"?
87888
I was reading some Java recently and came across something (an idiom?) new to me: in the program, classes with multiple constructors would also always include a blank constructor. For example:   public class Genotype {   private boolean bits[];   private int rating;   private int length;   private Random random;    public Genotype() {              //  &lt;= THIS is the bandit, this one right here     random = new Random();   }    /* creates a Random genetoype */   public Genotype(int length, Random r) {     random = r;     this.length = length;     bits = new boolean[length];      for(int i=0;i&lt;length;i++) {         bits[i] =random.nextBoolean();     }   }    /* copy constructor */   public Genotype(Genotype g,Random r) {     random = r;     bits = new boolean[g.length];     rating = g.rating;     length = g.length;      for(int i=0;i&lt;length;i++) {         bits[i] = g.bits[i];     }    } }   The first constructor doesn't seem to be a "real" constructor, it seems as though in every case one of the other constructors will be used. So why is that constructor defined at all?
22047
In Visual Studio, How do I show all classes inherited from a base class?    For example, in ASP.NET MVC there are several '' types -- and they all inherit from / implement the base class ActionResult.    It looks like unless you just 'know' that View and Json are valid ActionResult types, there is no way you can easily find this information out.    Please prove me wrong.  Is there something in the object browser that makes this easy to find out?  I'm even up for suggestions of tools outside of Visual Studio to discover this information about various classes.  For example: is there something in Resharper that will help me out?
20825
If I inherit from a base class and want to pass something from the constructor of the inherited class to the constructor of the base class, how do I do that?  For example, if I inherit from the Exception class I want to do something like this:  class MyExceptionClass : Exception {      public MyExceptionClass(string message, string extraInfo)      {          //This is where it's all falling apart          base(message);      } }   Basically what I want is to be able to pass the string message to the base Exception class.
72314
In "", Mark Lutz mentions "mixins". I'm from a C/C++/C# background and I have not heard the term before. What is a mixin?   Reading between the lines of  (which I've linked to because it's quite long), I'm presuming it's a case of using multiple inheritance to extend a class as opposed to 'proper' subclassing. Is this right?   Why would I want to do that rather than put the new functionality into a subclass? For that matter, why would a mixin/multiple inheritance approach be better than using composition?  What separates a mixin from multiple inheritance? Is it just a matter of semantics?
104128
I sometimes notice programs that crash on my computer with the error: "pure virtual function call".  How do these programs even compile when an object cannot be created of an abstract class?
33547
If I have an abstract parent class like this:  abstract class Vehicle {     public Vehicle(Person driver) {         //     } }   and then I create a child class like this:  public class MagicCarpet extends Vehicle {     //this won't compile }   I encounter the following Compile Error:     Error: Parent class has no 0-argument constructor for implicit construction at line ... column ...   Obviously I can explicitly re-declare a constructor on the child class toget it to compile:  public class MagicCarpet extends Vehicle {     public MagicCarpet(Person driver) {         super(driver);     } }   But I feel this isn't DRY. Not sure what's actually going on under the covers here.  How can I get a constructor (other than the implicit 0-argument one) to be inherited by a child class?
48031
If I have several classes with functions that I need but want to store separately for organisation, can I extend a class to have both?  i.e. class a extends b extends c  edit: I know how to extend classes one at a time, but I'm looking for a method to instantly extend a class using multiple base classes - AFAIK you can't do this in PHP but there should be ways around it without resorting to class c extends b, class b extends a
44955
I am looking for a reference on mathematically strict definition of class. For example, how do you construct the class of all ZFC-sets?
40477
In C#, if I have an inherited class with a default constructor, do I have to explicitly call the base class' constructor or will it be implicitly called?  class BaseClass {     public BaseClass()     {         // ... some code     } } class MyClass : BaseClass {     public MyClass() // Do I need to put ": base()" here or is it implied?     {         // ... some code     } }