Quantcast
Channel: What are the rules for calling the base class constructor? - Stack Overflow
Viewing all articles
Browse latest Browse all 22

Answer by edW for What are the rules for calling the base class constructor?

$
0
0

If you have default parameters in your base constructor the base class will be called automatically.

using namespace std;class Base{    public:    Base(int a=1) : _a(a) {}    protected:    int _a;};class Derived : public Base{  public:  Derived() {}  void printit() { cout << _a << endl; }};int main(){   Derived d;   d.printit();   return 0;}

Output is: 1


Viewing all articles
Browse latest Browse all 22

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>