Hi everyone,
I overloaded the addition operator for pointer notation in my assignment and I keep getting this error when I compile:
3 overloads have similar conversions
could be 'char *operator +(int,const String &)'
or 'String operator +(char,String &)'
or 'String operator +(const String &,const String &)'
while trying to match the argument list '(int, String)'
note: qualification adjustment (const/volatile) may be causing the ambiguity
It is happening at this part of the code:
And these are my overloaded operators...Code:void test15() { cout << "15. Testing S15: Pointer notation." << endl << endl; csis << "15. Testing S15: Pointer notation." << endl << endl; String s15("ABCDE"); for(int i = 0; i < s15.getLength(); i++) ++(*(s15+i)); for (int j = 0; j < s15.getLength(); j++) { cout << *(j + s15); csis << *(j + s15); } cout << endl; csis << endl; wait(); }
I believe this is the one it should be using for the pointer notation in this case:
Code:char* operator+(int index, const String& str){ char* value; value = new char[1]; value[0] = str.buf[index]; return value; }The following one isn't even supposed to be used for pointer notation, but it came up in the error...Code:char* operator+(const String& str, int index){ char* value; value = new char[1]; value[0] = str.buf[index]; return value; }
So this means that the compiler doesn't know which one to use right? Did I overload them incorrectly?Code:String operator+(char a, String& str){ int len = str.length; int count = 0; char* temp; temp = new char[len]; for(int i = 0; i < str.length; i++){ temp[i] = str.buf[i]; count++; } temp[count + 1] = a; return temp; }
Thanks for any help!



LinkBack URL
About LinkBacks


