[Dev-C++] Operator overloading for built in types.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: David M. <ci...@ya...> - 2003-12-27 14:37:37
|
Ok here is my dilema.
Scattered throught my code is the following line:
if(!strcmp(var1,var2))
....
What would be the best way to change that to
if( var1 == var2 )
....
So far here is some exaple code that illustrates my problem:
bool operator==(char *s1, char *s2)
{
if(!strcmp(s1,s2))
return true;
else
return false;
}
int main()
{
char x[10] = "Hello";
char y[10] = "Hello";
if(x == y)
cout << "Equal" << endl;
else
cout << "Not equal" << endl;
cin.get();
return 0;
}
Error:
C:/Documents and Settings/David/My Documents/scratch.cpp:9: `bool
operator==(char*, char*)' must have an argument of class or
enumerated type
What does it mean?? I have done operator overloading with various
classes but I can't get it to work with char *, please help. There is
no one to make it a friend with so that is ruled out.
=====
Signed
David Mcken
Life Sucks
Live with it
__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/
|