After figuring out my past problem (no instance of an overloaded function), I've come across another problem.
[IMG]http://i.imgur.com/SvX1l.png[/IMG]
I've pinpointed the code where I know the error is originating from:

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:

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.

Recommended Answers

All 4 Replies

Normally it's bad practice to operate directly on the memory the std::string class is managing for you, that's why the pointer returned is a [b]const[/b] char * .

You'll probably have to copy the string data to avoid getting error messages.

i.e.,

char *buffer = new char[data.size()+1];
strcpy(buffer,data.c_str());
//buffer is now what you can modify, but you must delete it with "delete [] buffer;"
int r = Decode_VL64(buffer);
delete [] buffer;
return r;
static int Decode_VL64(const std::string &data){
	char* chars = (char*)data.c_str();
	return Decode_VL64(data);
 
}

This function will never, ever end. It's recursive. You're calling the function again at the end every time, over and over and over and over and over...... until finally the stack has no room left to call the function. When the stack has no room left, the error is known as a "stack overflow", which is what your error message says. The two common reasons for this are recursive functions recursing too far, and trying to store too much data on the stack. You've got a recursive function out of control.

Here, this line:
return Decode_VL64(data);
You're calling the function again.

commented: gj, missed that totally lol. +9

Normally it's bad practice to operate directly on the memory the std::string class is managing for you, that's why the pointer returned is a [b]const[/b] char * .

You'll probably have to copy the string data to avoid getting error messages.

i.e.,

char *buffer = new char[data.size()+1];
strcpy(buffer,data.c_str());
//buffer is now what you can modify, but you must delete it with "delete [] buffer;"
int r = Decode_VL64(buffer);
delete [] buffer;
return r;

I'm still getting the same error :S
Usage:

cout << Decode_VL64(cats);

cats is a string variable I take in through user input.

static int Decode_VL64(const std::string &data){
	char* chars = (char*)data.c_str();
	return Decode_VL64(data);
 
}

This function will never, ever end. It's recursive. You're calling the function again at the end every time, over and over and over and over and over...... until finally the stack has no room left to call the function.

Here, this line:
return Decode_VL64(data);
You're calling the function again.

What would you suggest I do?

What would you suggest I do?

Don't call it again. Maybe you don't know how to use "return". Here is how I think you meant to write your function. See how I just return the char pointer?

static char* Decode_VL64(const std::string &data){
	char* chars = (char*)data.c_str();
	return (chars);
 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.