Convert char to char*

Hello, this is my first post. My question is how would I convert a char to a char*.

WHat I am do is making overloaded constructors that will handle different types of input and process them accordingly.

I'm still working on my c++ terminology so please forgive me if what I say isn't correct

For the previous constructor, I have the following:

String::String(char* a){
length = strlen(a);
buf = new char[length+1];
strcpy(buf, a);
}
String::String(char a){

}
I'd prefer a web page link to some information on how to do what I am looking to do rather than to be explicitly told what to do. Any help would be much appreciated. Ohya, i'm not allowed to any of the preexisting string class because we're trying to write our own.

Thanks,

Martin
Last edited on
You have pointer ownership problems with your string class.

When the user constructs one of your Strings from a char*, you simply copy the pointer they give you, which means that the caller owns the memory that is pointed to by the pointer you copied. If the caller then frees the memory, your String object now has a dangling pointer.

So per your request I won't solve that problem for you. You need to solve that problem first. Once you've solved it, the answer to your second constructor becomes clearer.

Topic archived. No new replies allowed.