I apologize in advance for the big footwoman in question

Tell me how to more correctly and beautifully implement the following functionality:

prehistory

I am processing an array of disparate objects (responsible for different statistics)

std::vector<...> objects; 

, united by some common minimal functionality ( .add , .get , .save , etc.) therefore, although the mentioned objects belong to different classes, I inherited all of them from one basic abstract class that defines the mentioned minimal functional

 std::vector<IBaseStatistics*> objects; object[0]->add(12.75); // пример использования 

Each object class (statistics) has its own initial input parameters, which are set when creating:

 objects.push_back(new CStatistics1(1, "data", true)); objects.push_back(new CStatistics2(L"unicode", 3.1415); 

task 1

But now I have a need for a new class that contains an array of the old class of a given type, i.e.

 class CStatictics_new: public IBaseStatistics { protected: std::vector<CStatistics1> m_inner; } 

At the same time, the new class requires both its initial input parameters and the input parameters used in the class array ( CStatistics1 ).


And I have a question - how to properly set these input parameters for the class CStatistics1?

2 ways come to mind (used the first one):

1) set the parameters for both classes in the constructor of the “main” class, ie:

 objects.push_back(new CStatistics_new( value1, value2, 1, "data", true )); 

store the received parameters of the CStatistics1 class as members of the CStatistics_new class and when you need to replenish the m_inner array use them

2) in the CStatistics1 class CStatistics1 store parameters as class members, add some clone method to create copies of the class and transfer to the CStatistics_new class the CStatistics_new class CStatistics_new created outside this class

What better way to do? Maybe there is 3 way, more correct and better, than what resulted above ?

problem 2

it later turned out that the CStatistics_new class CStatistics_new needed for working with other types and I made it just template

 template <class ICustomStatistics> class CStatictics_new: public IBaseStatistics { protected: std::vector<ICustomStatistics> m_inner; } 

but after that, there were problems with passing parameters for the ICustomStatistics class in the constructor of the CStatictics_new class and the first described method no longer works, i.e. only the second remains

What can be done in this case?

PS

those. The main question is how to pass different parameters for classes within other classes.

    0