Paul R wrote:
>>> countOutp->value(GetCountString());  //output as c style string

>>> const char* ListBuilder::GetCountString()
>>> {
>>>     string outputStr;           //temp output string
>>>     ostringstream countVal;     //convert int value to string
>>>     countVal << count;          //convert count integer to char string
>>>     outputStr = countVal.str(); //assign contents to string object
>>>     return outputStr.c_str();   //return as c style string
>>> }

>> Your string goes out of scope as soon as the function returns [..]

        Another way to fix it might be to change the return type of
        GetCountString() from "const char*" to "string",
        and change the value() call to
        countOutp->value(GetCountString().c_str()).

        The lifetime of the temporary string will then live
        long enough through the return of the function to
        reach value() before it gets deallocated.

        Assuming value() makes an internal copy of the string,
        all should be good, and this avoids the need for a
        reentry-unsafe static variable in the function.
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to