Berkeley CSUA MOTD:Entry 27618
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/30 [General] UID:1000 Activity:popular
5/30    

2003/3/7-8 [Uncategorized] UID:27618 Activity:nil
3/7    C++ Question: what is the purpose of the following?
       Derived::Derived() : Base("foo", "bar") {
               // constructor stuff here...
       }
       Base is the superclass of Derived.  I know the stuff following
       the single colon is the initialization list, but why is it calling
       the parent class's constructor?  Isn't that done automatically?
       TIA.
        \_ if parent class is listed in the initialization list, it calls
           the constructor that has those parameters.  Otherwise the
           default constructor (w/ no parameters) is called