Hello,
I was mildly surprised when I realized that I cannot initialize the vector directly like in the commented out command, but have to use a default constructor. Surprised because initialization directly via the constructor (i.e. without a unique pointer) works fine. I am doing this right, or is there a better way? Because doing it this way on a class with many vectors bloats the code.
Code:
#include <iostream>
#include <memory>
#include <vector>
struct Gauge
{
std::vector<int> Dial;
Gauge() = default;
Gauge(std::vector<int> dial) : Dial(dial) {}
};
int main ()
{
// auto gauge = std::make_unique<Gauge> ({1,2});
auto gauge = std::make_unique<Gauge> ();
gauge->Dial = {1,2};
std::cout << gauge->Dial[0] << '\n';
}