Greetings,
i'm making a function with an option argument which must be a string. Is there any way to do that without having the string as const char*? (i'd prefer to not use the string type).
Usage example:
void function(int a, int b = 0, char* str = "default") {}
foo(..., blah, etc); //blah is a non const pointer here, but you should not attempt to re-assign the pointer or bad things will happen. You can change the string data, of course. It IS effectively a const pointer, but the const is lost in the shuffle, and that isnt really a good thing but it does what you asked for.
you could also say
char *str = 0
and then handle the pointer depending on whether it was null or over-ridden by the user...
You cannot legally do char* str = "string literal";
in C++.
To give a better answer, we'd need to know more about how you're using the data. Is sounds like you want to modify the string? You can't modify string literals.
Going off what jonnin said, but with a slight change, maybe you want something like this...