Conditional call to base constructor

Currently, I have a based class with two different constructors:

class Base {
public:
   Base(std::string filname){...}
   Base(int a, int b) {...}
};

and a derived class of Base class. What I would like to do is to choose which constructor call inside the constructor of the derived class, but not in the initializer list. Something like this:

class Derived : public Base {
public:
    Derived() {
        if( /* exists("myFile") */ )
            this->Base("myFile");
        else
            this->Base(1,2);
    }
}

Is it possible to do that?, or because the base class is initialize before the derived class, the only way to call to the base constructor is in the initializer list?

Thanks

Answer

The choice of which base constructor is called happens before the body of the function and there’s no way to change it at run time like that. However, you might be able to get close. If the base class also has a move constructor, or you could you add one, you could use that:

class Derived : public Base {
public:
    Derived()
        : Base{ exists("myFile") ? Base{"myFile"} : Base{1, 2} } {
    }
}

This will call exists("myFile"); if that returns true, it will construct a temporary Base using the first constructor, and if it returns false it will construct a temporary Base using the second constructor. Either way, it will then construct the actual base subobject using this temporary.