Hello together,
I am relatively new to C++. After investing quite some time researching and
trying I am posting my problem here.
To illustrate the problem, i am posting what is working so far.
In the class initializePipeData values are hardcoded which are used
in another class.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class initializePipeData {
public:
int N_pipe = 200;
int N_flash = 1000;
double flashTol = 1e-7;
double blasiusExp = 0.2;
double pipeRough = 0.00007;
private:
};
|
In the second class the main calculations are done, first a result matrix is
declared.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
class PipePressureDrop : public initializePipeData {
public:
PipePressureDrop::PipePressureDrop() : sVp(N_pipe, std::vector<double>(26)) {}
std::vector<std::vector<double>> dp_Pipe(double L_pipe, double alpha, double d_pipe...) {
for (int i = 0; i < N_pipe; i++) {
switch (i){
case 0:
sVp.at(0).at(0) = 0;
...
|
So in order to fill the solution vector sVp the vector size N_pipe is needed. In case it is hard coded like in the example above it is working fine.
But what i want ist that int N_pipe, int N_flash etc. are received via a GUI.
I tried to do the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
class initializePipeData {
public:
int N_pipe;
void SetN(int n);
int GetN(void);
int N_flash = 1000;
double flashTol = 1e-7;
double blasiusExp = 0.2;
double pipeRough = 0.00007;
private:
};
|
and outside the class:
1 2 3 4 5 6 7 8
|
void initializePipeData::SetN(int n) {
N_pipe = n;
}
int initializePipeData::GetN(void) {
return N_pipe;
}
|
and then in the body file the following to pass the value of N_pipe to the class:
1 2 3
|
initializePipeData iniD;
iniD.SetN(200);
|
It is compiling fine, but when executing i get the error:
Exception at 0x7552DAD8
Exception: std::length_error
I has to do with the declaration of the size of the solution vector.
Not sure if I am expressing myself and the problem right.
It would save my weekend if someone could help me ;-)
Thanks in advance!
Greetings
dajoao