I am using someone elses function that takes:
optimise(std::vector<double> &input)
It edits the input.
How should I pass a vector to this, I have tried:
std::vector<double> input;
input.push_back('several points');
optimise(input);
This has a linker error saying:
undefined reference to optimise(std::vector<double, std::allocator<double> >&)
If i try this:
std::vector<double> &input;
input.push_back('several points');
optimise(input);
Then there is a compile error:
'input' declared as reference but not initialised
How do I initialise a reference to the vector or am I doing something completely wrong.
EDIT:
I wasn’t linking a library correctly in my CMakeLists. Thanks for everyone’s help, i wish i could mark you all as correct.
Your first way of passing the
vectoris correct. The compiler recognizes that the vector is passed to the function by reference from the signature in the header, makes a reference to your vector, and passes it to the function. The fact that you see linker errors tells you that the compile stage completed successfully.The linker error is there because you are failing to include the library where the
optimisefunction is implemented.