I'm trying to do the simply task of passing a vector to a function as a reference, and the modify the vector within the function. However, I get some pretty incomprehensible errors with the following example:
// data.h
class data {
public:
std::string a;
double b;
uint8_t c;
};
We make a vector of these data objects in the MainWindow class:
// MainWindow.h
class MainWindow {
public:
std::vector<data> vec;
void needs_vec(std::vector<data> &vec);
};
Below I've got the troublemaker function, along with the constructor of the MainWindow object which is where everything comes together.
// other_file.h
void needs_vec(std::vector<data> &vec) {
for (auto &vec: vec) {
vec.b = get_a_number();
}
};
// MainWindow.cpp
MainWindow::MainWindow() {
// Read a configuration file and initialize the vector
this->vec = read_config();
// Try to apply our function
needs_vec(this->vec);
// Continue doing other things
};
I've also tried playing around with rvalue references but I meet similar results: an indecipherable twenty page error message.