I'm having some difficulties in understanding the topic which I stated above.Can anyone here provide some good examples and references which will help me in future.
There is no easy way to do this, as classes can be derived from multiple other classes. There is no way to tell with a single command in what super class you want to call the constructor.
If you make a function that initializes everything, I believe that you can use ((BaseClass) instance_of_derived_class).init();. I am not positive on this one though.
There is no easy way to do this, as classes can be derived from multiple other classes. There is no way to tell with a single command in what super class you want to call the constructor.
If you couldn't do this, how would you make a class work like this:
1 2 3 4 5 6 7 8 9
class Base {
public:
Base(int x) {}
};
class Derv : public Base {
public:
Derv(int x) {} //how to call Base(int x) here?
}
There are two ways. Either you explicitly call a base constructor in mem-initializer list or you use a using declaration of the base constructor name in the derived class.
EDIT: Here is an example but you should find the compiler that will compile the code because not all compilers support inheriting constructors.:)