<pre>#include <iostream> #include <cstdlib> #include <memory> #include <map> using namespace std; class InputScale { public: float offset; float factor; }; int main() { bool inputSelected = true; map<int, unique_ptr<InputScale>> inputScales; map<int, unique_ptr<InputScale>> tachoScales; // version linked to one single map. auto& inputScale = inputScales[1]; inputScale = make_unique<InputScale>(); inputScale->offset = 1.f; std::cout << inputScale->offset << std::endl; // version to link to different map map<int, unique_ptr<InputScale>>::mapped_type* scale{ nullptr }; if (inputSelected) scale = &inputScales[2]; else scale = &tachoScales[2]; *scale = make_unique<InputScale>(); (*scale)->offset = 2.f; std::cout << (*scale)->offset << std::endl; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)