There are arrays, dynamic two-dimensional, which are formed as a result of mathematical operations. I need to combine several arrays into one and pass to a function. Many arguments passed to the function looks like Krivoruk.

int i=10000; double *aX = new double [i]; double *aCxmp = new double [i]; double *aCxmp1 = new double [i]; double *aCxcc = new double [i]; double *aCxcc1 = new double [i]; ... QList<QPointF> TconstSeriesZero; QList<QPointF> TconstSeriesOne; QList<QPointF> TconstSeriesTwo; QList<QPointF> TconstSeriesThree; QList<QPointF> TconstSeriesFour; ... TconstSeriesOne.append(QPointF(aX[i],aCxcc[i])); TconstSeriesZero.append(QPointF(aX[i],aCxmp[i])); TconstSeriesThree.append(QPointF(aX[i],aCxcc1[i])); TconstSeriesTwo.append(QPointF(aX[i],aCxmp1[i])); TconstSeriesFour.append(QPointF(aX[0],aCxcc1[i])); 

As TconstSeriesOne, TconstSeriesZero, TconstSeriesThree, TconstSeriesTwo, TconstSeriesFour - all these series to drive into one Tconst and transfer to the Chart chart.h function in one array:

 #ifndef CHART_H #define CHART_H #include <QString> class Chart { public: Chart(QString Titel, QString abscissaX, QString ordinatusY, double xMin,double xMax,double yMin,double yMax,Tconst); QString Titel,abscissaX,ordinatusY; double xMin,xMax,yMin,yMax; }; #endif // CHART_H 

How can we get and process this large Tconst array in the function itself, so that all charts of chart.cpp are drawn from:

 ..... Chart::Chart(QString Titel,QString abscissaX,QString ordinatusY, double xMin,double xMax,double yMin,double yMax,Tconst) { ... //![4] QLineSeries *diagramaForm6SeriesZero = new QLineSeries; diagramaForm6SeriesZero->setName("Диаграмма 1"); diagramaForm6SeriesZero->append(Form6SeriesZero); chart->addSeries(Tconst[0]); diagramaForm6SeriesZero->attachAxis(axisX); diagramaForm6SeriesZero->attachAxis(axisY); //![4] ... } 
  • not a damn thing is clear what you want / try to do ... try to explain yourself either within the framework of purely abstract concepts or rigidly in terms of c ++ - Fat-Zer
  • just make a class to which you add all these arrays as class variables (converting them to std :: vector or QVector along the way). Thus the transfer to the function will be trivial. - KoVadim
  • @ Fat-Zer I want to combine several arrays into one - Ivan Triumphov

2 answers 2

For a fixed number of Tconst lists, you can define this:

 QList<QPointF> *Tconst[]={&TconstSeriesZero,&TconstSeriesOne,&TconstSeriesTwo,&TconstSeriesThree,&TconstSeriesFour}; 

In the parameters of the function, then it will look like this:

 Chart(QString Titel, QString abscissaX, QString ordinatusY, double xMin,double xMax,double yMin,double yMax,QList<QPointF> **Tconst) 

And in the function itself, access by index:

 chart->addSeries(*Tconst[0]); 

For std :: vector <>

 std::vector<QList<QPointF> *> Tconst; Tconst.push_back(&TconstSeriesZero); Tconst.push_back(&TconstSeriesOne); Tconst.push_back(&TconstSeriesTwo); Tconst.push_back(&TconstSeriesThree); Tconst.push_back(&TconstSeriesFour); 

In the parameters of the function:

 Chart(QString Titel, QString abscissaX, QString ordinatusY, double xMin,double xMax,double yMin,double yMax,std::vector<QList<QPointF> *> &Tconst); 

In the function body, brute force arrays:

 for(unsigned int i=0;i<Tconst.size();++i) { chart->addSeries(*Tconst[i]); } 
  • It seems to be a good solution, but how to get the size of * Tconst? So * Tconst [] -> size (); error: expected primary-expression before ']' token? - Ivan Triumphov
  • How can I run through all the values ​​passed? In the cycle for - Ivan Triumphov
  • @IvanTriumphov You can pass as a separate parameter, you can take a constant, if their number is always the same, but you can place the links not in an array, but in a container of type stl :: vector <QList <QPointF> *>, which has a size () method gives the number of elements. - MindCleaner
  • @IvanTriumphov what is the difficulty with the for loop? - MindCleaner
  • I can not determine the size of how many graphs should draw. Could you in the answer rewrite as will be with std :: vector <QList <QPointF> *> and in for output to display all these graphs? - Ivan Triumphov

You can in different ways, for example:

  std::generate_n(Tconst, i, [aX]() { static auto ptr = ax; return *ptr++; }); std::generate_n(&Tconst[i], i, [aCxmp]() { static auto ptr = aCxmp ; return *ptr++; }); std::generate_n(&Tconst[2*i], i, [aCxmp1]() { static auto ptr = aCxmp1; return *ptr++; }); 

well, etc. But for Tconst you need to ensure that you Tconst n’t go beyond the limits, so it’s better to make it a vector and put it at the end of the vector

  • I can't get a few arrays in this way. Error: capture of non-variable 'Gradual_reset :: ax'. If possible in more detail - Ivan Triumphov
  • why does it work out for me? ... - AR Hovsepyan
  • Yes, I read your question inattentively, well, listen to the advice of KoVadim - I think he offered a good option - AR Hovsepyan