c++ - const char* variable as parameter to function -


I have this constructor in C ++ Library (by someone else, not by me):

< Pre> variable (const char * s)

which I want to use in my own function, useful (). This work is useful (), calculates an int, which I want to pass in the form of constellation variables (const char * s) as parameters.

That's why I am converting int to string and then transmitting a cons four * data type and I am transmitting the variable constructor as a parameter, but I get an error message.

Based on the integer in the variable LoopOi, I am creating a string "xi", where I have loops [0] = 2 for the integer example, with vector loopoi, then we make string "x2" , Which is then converted into a const char * , and then transmitted to Construct Variables (Const char * s).

My work is useful () in the following way:

  zero-free () {vector & lt; Int & gt; LoopsOE; LoopsOE.push_back (i) for (unsigned int i = 0; i & lt; 6; i ++); (Unsigned int i = 0; i & lt; loopsOE.size (); i ++) {// converting int to string std :: ostringstream sstreamComplete; SstreamComplete & lt; & Lt; LoopsOE [i]; Std :: string loopsOEStr = sstreamComplete.str (); // String Variable "xi" creation of string varPoly ("x"); VarPoly.append (loopsOEStr); // Change the string to four * const four * varPolyConverted = varPoly.c_str ()} std :: vector & lt; Polynomial_t & gt; Vec (myEdgesIntersect.size ()); Variable V (varPolyConverted); }  

When I try to compile this function, I get the following error message:

QSweepComplete.cpp: Member Function 'Zero QSweepComplete :: prealexMatrix () ': QSweepComplete.cpp: 975: Error:' varPolyConverted 'was not declared in this scope: *** [.obj / QSweepComplete.o] Error 1

Still I do not understand that I am modifying the function with a simple stability as follows:

  Modify useful to zero (vector & lt; Int & gt; LoopsOE; LoopsOE.push_back (i) for (unsigned int i = 0; i & lt; 6; i ++); (Unsigned int i = 0; i & lt; loopsOE.size (); i ++) {// converting int to string std :: ostringstream sstreamComplete; SstreamComplete & lt; & Lt; LoopsOE [i]; Std :: string loopsOEStr = sstreamComplete.str (); // String Variable "xi" creation of string varPoly ("x"); VarPoly.append (loopsOEStr); // Change the string to four * const four * varPolyConverted = varPoly.c_str ()} std :: vector & lt; Polynomial_t & gt; Vec (myEdgesIntersect.size ()); Const char * str = "x0"; Variable V (str); }  

The function compiles and runs without any problems.

If anyone has any suggestions, then I would greatly appreciate him.

Thank you. Best wishes, Madeleine

varPolyConverted variable only appears inside the loop and you Try to use it after the loop - This moment is not allowed, because the variable is out of the scope of that time. This is the reason why the compiler refuses to compile the code.

You have to change your code so that you can only use it within the variable - either either loop it out or call the function inside the loop. / P>

Be careful if you choose the pre - you have many STL objects and you want one of them buffer an indicator - the object must have at least one scope because the indicator buffer Otherwise you run into undefined behavior.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -