Ich habe versucht, die Lösung zu finden und recherchiert für einen, habe aber immer noch keinen gefunden.Was bedeutet "error: passing 'const String' als 'dieses' Argument verwirft Qualifier [-fpermissive]" bedeuten?
Ich erhalte diesen Fehler für meinen String.cpp:
error: passing ‘const String’ as ‘this’ argument discards qualifiers [-fpermissive]
if(_length != two.length())
^
String.cpp:59:5: note: in call to ‘int String::length()’
int String::length()
String.cpp: In member function ‘bool String::add(const String&) const’:
String.cpp:115:32: error: passing ‘const String’ as ‘this’ argument discards qualifiers [-fpermissive]
for(int i = 0; i < two.length(); i++)
^
String.cpp:59:5: note: in call to ‘int String::length()’
int String::length()
^
String.cpp:116:15: error: increment of member ‘String::_length’ in read-only object
data[_length++] = two.at(i);
^
String.cpp:116:29: error: passing ‘const String’ as ‘this’ argument discards qualifiers [-fpermissive]
data[_length++] = two.at(i);
^
String.cpp:76:6: note: in call to ‘char String::at(int)’
char String::at(int index)
Und ich weiß wirklich nicht, wie man es beheben?
Hier ist meine String.cpp:
bool String::equal(const String &two) const
{
if(_length != two.length())
return false;
for(int i = 0; i < _length; i++)
if(data[i] != two.at(i))
return false;
return true;
}
bool String::add(const String &two) const
{
for(int i = 0; i < two.length(); i++)
data[_length++] = two.at(i);
data[_length] = '\0';
return true;
}
Und hier ist meine String.h Datei: { privat:
int _length;
char *data;
int getCharArraySize(char arr[]);
public:
String();
String(char str[]);
String(const String &);
virtual ~String(); //Destructor should delete your data pointer.
int length();
void clear();
bool empty();
char at(int index);
int find(char substr[], int startIndex);
bool equal(const String &) const;
bool add(const String &) const;
void print() const;
void operator<<(const String &) const;
bool operator==(const String &) const; //Should replace your equal() method.
bool operator+(const String &) const; //Should replace your add() method. Should append the char* in two to the object doing the calling. Return true if you were able to add the two together, false if not.
void operator=(const String &) const; //Should assign two to the calling object.
char operator[](int index) const; //Should replace your at() method.
};
Ok danke das hat geholfen. –