I'm trying to create an custom array...but I'm having trouble with my constructor from a literal....if I compile without doing a call from a string literal it's fine, but if a do as you can see below it launch an error...anyone knows why?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
String(const std::string&& str){ //here is the problem
size = str.length();
ptr = new C [size];
std::stringstream line(str);
C unit;
int cont = 0;
while(line>>unit){
ptr[cont] = unit;
cont++;
}
ptr[cont] = '\0';
}
1 2 3 4 5 6 7 8 9 10 11
int main(){
String<char> my{"this is not working"};
return 0;
}
length() function doesn't include the null terminated character?
No, it does not.
Looking at the rest of your code, I think you could benefit from the reminder that valid indexes for an array of size n are 0 through n-1, because it doesn't observe this rule in quite a few places.
If your String class is templated on the character type, don't you think you should be using that type in your data members?