[C++]Help with toCharArray()?
[Forgot the title]
After figuring out my past problem (no instance of an overloaded function), I've come across another problem.
http://i.imgur.com/SvX1l.png
I've pinpointed the code where I know the error is originating from:
PHP Code:
static int Decode_VL64(const std::string &data){
char* chars = (char*)data.c_str();
return Decode_VL64(data);
}
What I'm trying to do here is pull off:
Code:
char[] chars;
chars = data.toCharArray();
return Decode_vL64(chars);
As native C++ doesn't have a method like toCharArray() built in, I googled around for an alternative and found referencing my char array as a pointer worked. However, that error is thrown. Does anyone have any suggestions as to why the error is being thrown, and can anyone suggest an alternative?
I don't want to reverse my encoding function, but if need be, I will have to.
re: [C++]Help with toCharArray()?
how're calling this function? you must see the callstack before assuming this is the problematic function.
btw, if you want the chars as an array, try this:
Quote:
std::vector<char> array (data.begin(), data.end());
array[0]...
array[1]...
re: [C++]Help with toCharArray()?
Well, you've not translated that code correctly... Your C++ code is recursively passing the data var to the same method. The C# code takes the string (data) and passes a char array to an overloaded method.
Posted via Mobile Device
re: [C++]Help with toCharArray()?
I fixed it, by removing the recursion.
PHP Code:
static string Decode_VL64(const std::string &data){
char* chars = (char*)data.c_str();
return (data);
}
However, this was useless for what I need it for =[
Re: [C++]Help with toCharArray()?
Now I don't even get what you're supposed to be doing... You're just passing a string to a method and having it return the exact same string. I think you need to study the C# code some more, as it's already obvious to me from the tiny bit of code that you posted that it's passing a char array to a method that decodes it. Your code doesn't actually do anything.
Re: [C++]Help with toCharArray()?
char* is for all intents and purposes an array. You're getting a stack overflow because you're writing too much to a local variable and obliterating the stack frame of the function (the ESP check MSVC puts in by default in debug mode is detecting this, the cookie pushed onto the stack is being overwritten).
Re: [C++]Help with toCharArray()?
Quote:
Originally Posted by
Yamachi
Now I don't even get what you're supposed to be doing... You're just passing a string to a method and having it return the exact same string. I think you need to study the C# code some more, as it's already obvious to me from the tiny bit of code that you posted that it's passing a char array to a method that decodes it. Your code doesn't actually do anything.
Yeah, I realised when I fixed it. I wrote a decoding function however. It works.