#include<iostream>
#include<string>
using namespace std;
class String
{
public:
String(){p=NULL;}
String(char *str);
void display();
friend bool operator>(String &string1,String &string2);
private:
char *p;
};
String::String(char *str)
{
p=str;
}
void String::display()
{
cout<<p;
}
bool operator>(String &string1,String &string2)
{
if(strcmp(string1.p,string2.p)>0)
return false;
else return true;
}
int main()
{
String string1("hello!"),string2("book!");
cout<<(string1>string2)<<endl;
return 0;
}
--------------------Configuration: vetor1 - Win32 Debug--------------------
Compiling...
vetor1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(24) : error C2248: 'p' : cannot access private member declared in class 'String'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(12) : see declaration of 'p'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(24) : error C2248: 'p' : cannot access private member declared in class 'String'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(12) : see declaration of 'p'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(31) : error C2593: 'operator >' is ambiguous
Error executing cl.exe.
vetor1.exe - 3 error(s), 0 warning(s)