I have a class C that inherits class P
template <typename T>
class P{
public:
P();
P(T* sometype);
};
class C: public P<sometype>{
};
Now would C hide P(sometype*) constructor ? But I need that P(ometype*) constructor be available in C. Do I need to write another C(sometype*) that calls parent constructor ? or there is some easy breakthrough. and I don;t want to use C++11 features.
Yes, constructors are not inherited. You need to write a new one for
C:Note, in addition, that your use of the identifier
sometypeis inconsistent. In the case ofPyou use it as a variable name, inCit is a typename, but one that hasn’t been declared.Another question is what the constructor of
Cis going to do about thesometypeobject. I suspect it is going to do exactly whatP‘s constructor does, and since you need to call the constructor of the base class anyway, your implementation of theCconstructor will most likely look like this:As a final remark: C++11 actually offers constructor inheritance as a feature. Since you are not interested in using C++11 features (which is a pity though indeed), and since the feature is not yet implemented by many compilers I won’t go into the details. The reference to the feature definition is here.