Quantcast
Channel: Comments on: 11.4 — Constructors and initialization of derived classes
Viewing all articles
Browse latest Browse all 159

By: manojg

$
0
0

What is the difference between these defnition of the derived classes constructors:

class Base
{
protected:
int a, b;
public:
Base() {}
Base(int aa, int bb) { a = aa; b = bb; }
};

class Derived : public Base
{
protected:
int c
public:
Derived() {}
Derived(int aa, int bb, int cc) { Base(aa, bb); c = cc; }
// OR
Derived(int aa, int bb, int cc) : Base(aa, bb), c(cc) {}
};

So, what is the difference between Derived(int aa, int bb, int cc) { Base(aa, bb); c = cc; } and Derived(int aa, int bb, int cc) : Base(aa, bb), c(cc) {}? First definition does not work but they look identical.


Viewing all articles
Browse latest Browse all 159

Trending Articles