zoukankan      html  css  js  c++  java
  • C++ class外的==重载,判断相等,测试等于,重载示例。二元操作符

    #include <iostream>
    
    // overloading "operator == " outside class
    // == 是二元操作符
    
    //////////////////////////////////////////////////////////
    
    class Rectangle
    {
    public:
    	Rectangle(int w, int h) 
    		: width(w), height(h)
    	{};
    
    	~Rectangle() {};
    
    	//bool operator== (Rectangle& rec);
    
    
    public:
    	int width;
    	int height;
    };
    
    //////////////////////////////////////////////////////////
    
    bool operator==(Rectangle & ths, Rectangle & rec)
    {
    	return ths.height == rec.height
    		&& ths.width == rec.width;
    }
    
    //////////////////////////////////////////////////////////
    
    int main()
    {
    	Rectangle a(40, 10);
    	Rectangle b(40, 10);
    	Rectangle c(4, 10);
    
    	std::cout << (a == b) << std::endl;
    	std::cout << (a == c) << std::endl;
    	std::cout << (b == c) << std::endl;
    
    	return 0;
    }
    

      

  • 相关阅读:
    XML与 实体的相互转化
    SerializeHelper
    Linq To Xml
    JsonHelper
    动态添加XtraTabControl的page页和子窗体
    窗体设置操作
    常用快捷键
    Jquery键盘事件
    Http跨域
    [转]ASP.NET母版页中对控件ID的处理
  • 原文地址:https://www.cnblogs.com/alexYuin/p/11965139.html
Copyright © 2011-2022 走看看