0

I encountered a cpp class MyClass that is inherited from another class called t1. The header file for MyClass looks like this (I only show the important part):

class MyClass : public t1 {
public:
    MyClass(ThisType *obj=0):t1(obj){}; 
...

Then at the t1.h, the constructor just read:

t1(ThisType *obj) : var_1(0) {...}

Based on my current understanding, the parametrized constructor in the t1.h just a normal one: it wants to assign 0 to a variable var_1 which is already defined in the header.

But for the MyClass.h case, there is no defined variable t1 in MyClass.h and evenMyClass.cppwhatsoever. So it is out of my expectation on how the parametrized consturctor works.

What is the best explanation for what exactly the line t1(obj) does ?

  • There is no such thing as a "parameterized constructor" in C++. Those are just the member initializer list, which any constructor can have.. – Nicol Bolas Oct 02 '22 at 03:08

0 Answers0