Passing a vector as function argument
-
Apologies if this is the wrong place but;
When defining a QVecotr with:QVector<double> x(temp),y(temp);How can I place this into a functions paramater definition?:
void MainWindow::plotGraph(int selectedIndex, QVector<double> x,y)As the x,y is causing a problem due to the comma.
-
Apologies if this is the wrong place but;
When defining a QVecotr with:QVector<double> x(temp),y(temp);How can I place this into a functions paramater definition?:
void MainWindow::plotGraph(int selectedIndex, QVector<double> x,y)As the x,y is causing a problem due to the comma.
@SOrton said in Passing a vector as function argument:
As the x,y is causing a problem due to the comma.
Because you don't assign a type for y - in a function call you can't use the shortcut as for a definition and have to properly define all parameters.
-
Apologies if this is the wrong place but;
When defining a QVecotr with:QVector<double> x(temp),y(temp);How can I place this into a functions paramater definition?:
void MainWindow::plotGraph(int selectedIndex, QVector<double> x,y)As the x,y is causing a problem due to the comma.
-
Apologies if this is the wrong place but;
When defining a QVecotr with:QVector<double> x(temp),y(temp);How can I place this into a functions paramater definition?:
void MainWindow::plotGraph(int selectedIndex, QVector<double> x,y)As the x,y is causing a problem due to the comma.
@SOrton said in Passing a vector as function argument:
QVector<double> x(temp),y(temp);
How can I place this into a functions paramater definition?:
void MainWindow::plotGraph(int selectedIndex, QVector<double> x,y)Ok First thing. You need to create a "using" or "typedef" declaration for your container, as an alias when refering to the type later in your code
using MY_VEC = QVector<double>;
MY_VEC v1(27U);
MY_VEC v2 = { 0.0, 1.0, 37.555 };
void someFunction(MY_VEC& v) { v.clear(); }
someFunction(v2);Finally, don't put multiple variable declarations on the same line. It's considered bad form by most modern coding standards.