Reputation: 21
My school project asks me to re-create the std::string class (with less detail). I'm having a small problem that I have two conflicting(?) constructors.
The problem is when I want to create a String from a single character. Instead of calling
String(char);
it calls
String(char[]);
How can I specify which constructor I would like called?
Update Wow, now I feel silly. I was calling using char* and not a char so of course it would call the array/pointer version. Thanks for making this painfully obvious to me :)
Upvotes: 0
Views: 364
Reputation: 1
Supposed you have the following
class String {
public:
String(char);
String(char[]);
};
you'll use
char charvar = 'X';
String s(charvar);
to call the 1st form, and
char strvar[] = "XXXX";
String s(strvar);
to call the second.
Beyond this your question is too unclear/unspecific, to give a concise answer for what you actually want to achieve.
Upvotes: 1
Reputation: 117876
You need to use single quotes to specify a char
otherwise it will consider it a char[]
with a single character (aside from the termination character)
'a' // char
"a" // char[]
Upvotes: 0