I have a function defined in the header file prog.h, which takes a couple of arguments of the type bool, string and double.
string createDataFolder(bool setPBC, string distribution, double timestep, double simtime, double potRange, double potStrength,
double particlesize, bool steric, bool ranRod, bool ranU, bool rand, double dvar, double polydiam, bool Pointq){
//...
if (Pointq) folder += "/pointq";
//....
return folder;
}
When I call the function from inside my main() function in prog.cpp via
string folder = createDataFolder(setPBC, distribution, timestep, simtime, urange, ustrength,
particlesize, includeSteric, ranRod, ranU, rand, dvar, polydiam, Pointq);
the bool parameter Pointq
is always passed as false
, no matter if it is set to true
or false
, even if I call the function as
string folder = createDataFolder(setPBC, distribution, timestep, simtime, urange, ustrength,
particlesize, includeSteric, ranRod, ranU, rand, dvar, polydiam, true);
If I change the definition of the function definition and call, such that there is another parameter after Pointq
, then Pointq
is passed correctly, and the last parameter as well.
string createDataFolder(bool setPBC, string distribution, double timestep, double simtime, double potRange, double potStrength,
double particlesize, bool steric, bool ranRod, bool ranU, bool rand, double dvar, double polydiam, bool Pointq, bool tmp){
//...
if (Pointq) folder += "/pointq";
//....
return folder;
}
string folder = createDataFolder(setPBC, distribution, timestep, simtime, urange, ustrength,
particlesize, includeSteric, ranRod, ranU, rand, dvar, polydiam, Pointq, true)
If I change the order of the last two arguments of the createDataFolder
function, it works as well.
string createDataFolder(bool setPBC, string distribution, double timestep, double simtime, double potRange, double potStrength,
double particlesize, bool steric, bool ranRod, bool ranU, bool rand, double dvar, bool Pointq, double polydiam){ ... }
I assume there is a stupid mistake in my code, but I don't know where to look, since I have no intuition, how such an error could occur. I've searched the forum for something similar in C++ but I was not able to find anything.
It would be great if somebody could provide me with some insights or point me to a relevant thread.
EDIT
Here's a minimal example that still produces the error on my machine
#include <iostream>
using namespace std;
void createDataFolder( double potRange, bool Pointq){
char range[5];
sprintf(range, "%.3f", potRange);
cout << "in createDataFolder Pointq is " << Pointq << endl;
}
int main(int argc, const char* argv[]){
bool Pointq = true;
double urange = 10;
cout << "In main(), Pointq is " << Pointq << endl;
createDataFolder( urange, Pointq);
return 0;
}