c++ - What are the rules for calling the superclass constructor? -


what c++ rules calling superclass constructor subclass one?

for example, know in java, must first line of subclass constructor (and if don't, implicit call no-arg super constructor assumed - giving compile error if that's missing).

base class constructors automatically called if have no argument. if want call superclass constructor argument, must use subclass's constructor initialization list. unlike java, c++ supports multiple inheritance (for better or worse), base class must referred name, rather "super()".

class superclass {     public:          superclass(int foo)         {             // foo         } };  class subclass : public superclass {     public:          subclass(int foo, int bar)         : superclass(foo)    // call superclass constructor in subclass' initialization list.         {             // bar         } }; 

more info on constructor's initialization list here , here.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -