Hey guys,
I'm having an unusual error with a string literal in my code.
Assume the constructor for MyStringClass looks something like this:
Now, when I go to call this constructor:
Now, I've used lines like the one above throughout my program, but it's only failing on one of them.
It turns out that the constructor IS actually working, but the char* which should be received as the parameter turns out to be a strange pointer which is not pointing to a string at all. Thus, when I go to use strlen in the constructor, it crashes.
My guess is that I'm doing something screwy to the memory before I try and use this line, and that's why it's only failing this time. For some reason, the string literal is not getting instantiated? What do you guys think?
Thanks for your help!
Nathan
I'm having an unusual error with a string literal in my code.
Assume the constructor for MyStringClass looks something like this:
- Code:
MyStringClass::MyStringClass(char* cCharsIn) {
int i = strlen(cCharsIn);
...
}
Now, when I go to call this constructor:
- Code:
MyStringClass* myString = new MyStringClass("hello");
Now, I've used lines like the one above throughout my program, but it's only failing on one of them.
It turns out that the constructor IS actually working, but the char* which should be received as the parameter turns out to be a strange pointer which is not pointing to a string at all. Thus, when I go to use strlen in the constructor, it crashes.
My guess is that I'm doing something screwy to the memory before I try and use this line, and that's why it's only failing this time. For some reason, the string literal is not getting instantiated? What do you guys think?
Thanks for your help!
Nathan