c++ 运算符重载

#include 
#include
#include
using namespace std;
class myString
{
private:
    char *str;      //记录C风格的字符串
    int size;       //记录字符串实际长度
public:
    //无参构造
    myString():size(10)
    {
        str=new char[size];//构造出一个长度为10的字符串
        strcpy(str,"");
        cout<<"myString::无参构造"<str=new char(*(other.str));
            strcpy(str,(other.str));
            this->size=other.size;
        }
        cout<<"myString::拷贝赋值"<str,R.str);
        return *this;
    }


    //重载运算符==
    bool operator==(const myString &R) const
    {
        if(strcmp(this->str,R.str)==0)
            return true;
    }

    //>运算符重载
    bool operator>(const myString &R) const
    {
        if(strcmp(this->str,R.str)>0)
            return true;
    }
    //<运算符重载
    bool operator<(const myString &R) const
    {
        if(strcmp(this->str,R.str)<0)
            return false;
    }

    //输出<<重载
    friend ostream &operator<<(ostream &L, const myString &O);    //将<<运算符重载函数设置成友元
    //输入>>重载
    friend istream &operator>>(istream &L, const myString &O);    //将>>运算符重载函数设置成友元

};

ostream &operator<<(ostream &L, const myString &O)
{
    L<>(istream &L, const myString &O)
{
    L>>O.str;
    return L;
}

int main()
{

    //有参构造
    myString s1("hello world");
    cout<<"s1:"<s4)
        cout<<"大小判断为true"<>"<>a;
    cout<<"a = "<

你可能感兴趣的:(c++,算法,java)