Hello!
I have this constructor implemented in a C++ library(by someone else, not by me):
Variables(const char *s)
Which I want to use in my own function, useful(). This functions useful(), computes an int which I want to be transmitted as a parameter to the constructor Variables(const char *s).
So I am converting the int to a string and then to a const char* data type. And them I am transmitted it as a parameter to the Variables constructor, but I get an error message.
Depending on the integers in the variable loopOE, I am constructing a string "xi", where i is the ith integer from the vector loopOE. For example is loops[0]=2, then we create the string "x2", which is then converted to a const char *
, and then transmitted to the constructor Variables(const char* s).
My function useful() looks in the following way:
void useful(){
vector<int> loopsOE;
for (unsigned int i=0;i<6;i++)
loopsOE.push_back(i);
for (unsigned int i=0;i<loopsOE.size();i++){
//convering int to string
std :: ostringstream sstreamComplete;
sstreamComplete << loopsOE[i];
std :: string loopsOEStr=sstreamComplete.str();
//construct the string variable "xi"
string varPoly("x");
varPoly.append(loopsOEStr);
//converting the string to char*
const char* varPolyConverted=varPoly.c_str()
}
std::vector< polynomial_t > Vec(myEdgesIntersect.size());
Variables V(varPolyConverted);
}
When I try to compile this function I get the following error message:
QSweepComplete.cpp: In member function 'void QSweepComplete::prealexMatrix()': QSweepComplete.cpp:975: error: 'varPolyConverted' was not declared in this scope make: *** [.obj/QSweepComplete.o] Error 1
Still I don't understand as if I modify the function with a simple constant in the following way:
void usefulModified(){
vector<int> loopsOE;
for (unsigned int i=0;i<6;i++)
loopsOE.push_back(i);
for (unsigned int i=0;i<loopsOE.size();i++){
//convering int to string
std :: ostringstream sstreamComplete;
sstreamComplete << loopsOE[i];
std :: string loopsOEStr=sstreamComplete.str();
//construct the string variable "xi"
string varPoly("x");
varPoly.append(loopsOEStr);
//converting the string to char*
const char* varPolyConverted=varPoly.c_str()
}
std::vector< polynomial_t > Vec(myEdgesIntersect.size());
const char * str="x0";
Variables V(str);
}
the function compiles and runs without any problems.
If anyone has any suggestions, I will strongly appreciate them.
Thanks in advance. Best wishes, madalina