0

How to write constructor for class B if it is a derived class of A? How to instantiate?

class A has an integer member, class B has a char member.

23rd Nov 2016, 1:51 PM
Marcell Juhasz
2 Respuestas
0
the same as you would for a normal class,the base classes constructor just gets called first.
23rd Nov 2016, 2:31 PM
Ángel Perales
Ángel Perales - avatar
0
class B : public A { public: A(int a) : member1(a) {}; B(char b) : member2(b) {}; }; *in main:* B *obj = new B(14, 's'); Is this ok?
23rd Nov 2016, 4:49 PM
Marcell Juhasz