[Bug c++/32944] New: operator= not ambiguous overload but does not compile
Dallas at ekkySoftware dot com
gcc-bugzilla@gcc.gnu.org
Tue Jul 31 12:19:00 GMT 2007
#include <string.h>
#include <stdio.h>
class CString{
public:
CString(){value = NULL;}
CString(char *initValue){
if(initValue != NULL) value = NULL;
else strcpy((value = new char[strlen(initValue)+1]),initValue);
}
~CString(){if(value != NULL) delete [] value;}
CString& operator=(char* newValue){
if(value != NULL) delete [] value;
if(newValue != NULL) value = NULL;
else strcpy((value = new char[strlen(newValue)+1]),newValue);
}
CString& operator=(CString& newValue){
if(value != NULL) delete [] value;
if(newValue.value != NULL) value = NULL;
else strcpy((value = new
char[strlen(newValue.value)+1]),newValue.value);
}
CString operator+(char *addValue){
CString tempValue;
strcpy((tempValue.value = new char[strlen(value) +
strlen(addValue) + 1]),value);
strcat(tempValue.value,addValue);
return CString(tempValue.value);
}
CString operator+(CString& addValue){
CString tempValue;
strcpy((tempValue.value = new char[strlen(value) +
strlen(addValue.value) + 1]),value);
strcat(tempValue.value,addValue.value);
return CString(tempValue.value);
}
char *value;
};
int main(int argc, char *argv[])
{
CString a("First String"), b("Second String"), c;
c = a + " - " + b;
printf(c.value);
}
--
Summary: operator= not ambiguous overload but does not compile
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Dallas at ekkySoftware dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32944
More information about the Gcc-bugs
mailing list