error C2662 cannot convert 'this' pointer from 'const n' to 'n &'
Getting this error...
error C2662: 'Txt::stringlength' : cannot convert 'this' pointer from 'const Txt' to 'Txt &'
What does it mean, please?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
class Txt {
unsigned int length;
char* text;
Txt();
Txt(char* t);
~Txt();
Txt operator+ (const char* t) const;
unsigned int stringlength(char* t);
};
Txt::Txt() {
};
Txt::Txt(char* t) {
length = stringlength(t);
text = new char[length + 1];
for (unsigned int i = 0; i <= length; i++) {
text[i] = t[i];
};
};
Txt::~Txt() {
delete[] text;
};
Txt Txt::operator+ (const char* t) const
{
unsigned int tlen = stringlength(t);
Txt temp;
temp.length = this->length + tlen;
temp.text = new char[temp.length + 1];
for (unsigned int i = 0; i < this->length; i++) {
temp.text[i] = this->text[i];
};
for (unsigned int i = 0; i <= tlen; i++) {
temp.text[i + this->length] = t[i];
};
return temp;
}
unsigned int Txt::stringlength(char* t) {
unsigned int i = 0;
while (t[i] != 0) {
i++;
}
return i;
}
|
Cheers
You may not apply function stringlength to a pointter that refers to const char.
Txt Txt::operator+ (const char* t) const
{
unsigned int tlen = stringlength(t);
Topic archived. No new replies allowed.