• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor


  • Subject: Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
  • From: John McCall <email@hidden>
  • Date: Fri, 18 Jan 2013 02:18:52 -0800

On Jan 18, 2013, at 1:28 AM, Rick Mann <email@hidden> wrote:
> Can anyone explain this error? It sure looks to me like all the base class constructors are being explicitly called.
>
> 	http://pastebin.com/cVMmgqCZ

This is off-topic for this list, but since I'm here anyway, I'll answer.  In the future, though, please take this to a venue that's more specific to C++.

In C++, a constructor must directly initialize all of the virtual bases of the class it appears in;  it cannot "inherit" initializers of virtual bases from its base-class constructors.  In turn, since all the virtual bases were already initialized by the most-derived class, those initializers are ignored when constructing base classes.

There are many reasons for this which could fill, if not a book, at least a small pamphlet;  suffice it to say that that's how it is.

And yes, this does make virtual bases without public default constructors very annoying to use.  (This is actually sometimes used as a hacky way to disable or limit subclassing:  first, add an empty virtual base with a private default constructor;  next, have that class befriend every class that you wish to allow to subclass your type.  If your class had a vtable anyway, this doesn't even bloat your object size, although it does make your vtables a bit bigger.)

I believe that most expert C++ programmers would say that virtual inheritance is something that you should use very carefully, if you really must use it at all.  Using it pervasively as your standard method of inheritance is almost certainly a sign of a poor class design.

John.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
      • From: Rick Mann <email@hidden>
References: 
 >constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor (From: Rick Mann <email@hidden>)

  • Prev by Date: Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
  • Next by Date: Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
  • Previous by thread: Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
  • Next by thread: Re: constructor for 'E' must explicitly initialize the base class 'C' which does not have a default constructor
  • Index(es):
    • Date
    • Thread