I am new to C++ and happen to come across a code which looks like this :
template<class T, class Composite> class CompositeTester: public Composite
{
public:
CompositeTester(T* instance, const typename Composite::Parameters& parameters) : Composite(parameters)
{
singletonInstances_[parameters.instanceIndex] = instance;
}
}
- The inheritance is not so clear to me, because the inheritance is from the template class arguments itself. What is this concept known as?
In the contructor
CompositeTester
, I realise that the instance ofComposite
is created withparameters
as arguments. But this syntax is quite difficult to understandconst typename Composite::Parameters
. How to intrepret this syntax? Is defining an object of class composite, even before it exists valid?singletonInstances_[parameters.instanceIndex] = instance
. Is here a new variable created forparameters.instanceIndex
? There exists no definition in the source code forclass Composite::Parameters
orclass Composite
apart from what I mentioned in the question here.