结构体运算符重载

文章目录

  • 结构体运算符重载(=、<、==)

结构体运算符重载(=、<、==)

结构体运算符重载
struct MyStruct
{
	int a;
	int b;
	std::string c;

赋值运算符重载
    MyStruct operator=(const MyStruct& other)
    {
        this->a = other.a;
        this->b = other.b;
        this->c = other.c;

        return *this;
    }

重载 < 运算符
    bool operator <(const MyStruct other)
    {
        if (this->a < other.a)
        {
            return true;
        }
        else 
        {
            return false;
        }
    }

重载 == 运算符
    bool operator ==(const MyStruct other) 
    {
        if (this->a == other.a && this->b == other.b)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

};

你可能感兴趣的:(C++,c++,结构体,运算符重载)