I'm working on some code in which a variable of type std::vector<double>
is declared, before the value is specified. I can't define the value together with declaration, because it takes many lines of code to set the value. The thing is that this variable is a constant in essence, meaning it shouldn't be modified once it's set. However, it can't be declared const
.
One way is to create another variable which is const
and copy the value into it. const std::vector<double> a(b);
would do, and use a
instead of b
in the program. However, my variable can be large and I wish to learn a way other than having to perform copying.
Any suggestions from you guys?