I am working on a project in C++ and its structure is the following:
ABC A, Derived (public inheritance) class B, Derived (public inheritance) class C. composed class D, whose private member data is: vector> matr.
This is my constructor in D:
D(A& o, const size_t& num, const string& element, const double& last, const func_t& function)
{
vector<double> vec = function(o[element], last, num);
**A& p(o);
shared_ptr<A> u(&p);**
vector<shared_ptr<A>> matrix(num, u);
for (size_t i = 0; i != matrix.size(); ++i)
{
matrix[i]->operator[](element) = vec[i];
}
matr = matrix;
}
what I am trying to do here is to create a vector of smart pointers to a COPY of the input A. The reason why I am trying to get a copy is that in the for loop I modify the object being pointed, but I do not want to modify the original object I use as input. I tried to use: const A& o, but then I do not manage to use the for loop.
In main.cpp, I'd like to:
B opt;
cout << B["U"] << endl; // output: 60
D(B, 3, "U", 80, my_function);
cout << B["U"] << endl; // output: 60, but here instead (without trying to make a copy, bold part of the code, I get 80 because D() modifies the original A& opt )
So I inserted the bold part of the code to try making a copy, but I get: Debug Assertion Failed is_block_type_valid(header->_block_use)
I cannot use template to perform this task.