User Tools

Site Tools


c_-_c_operator_overloading:logical_operator_overloading

C - C++ Operator Overloading - Logical Operator Overloading

#include <iostream>
#include <cstdlib>               // For random number generator
#include <ctime>                 // For time function
using std::cout;
using std::endl;
 
class Box 
{
public:
  Box(double aLength, double aWidth, double aHeight):length(aLength), width(aWidth), height(aHeight) {}
 
  double volume() const 
  {
    return length*width*height;
  }
 
  double getLength()  const { return length; }
  double getWidth() const { return width; }
  double getHeight()  const { return height; }
 
  inline bool operator<(const Box& aBox) const 
  {
    return volume() < aBox.volume();
  }
 
  inline bool operator<(const double aValue) const 
  {
    return volume() < aValue;
  }
 
private:
  double length;
  double width;
  double height;
};
 
 
int main() 
{
  Box firstBox(17.0, 11.0, 5.0);
 
  if(firstBox < 100000)
  {
    cout << "less than";
  }
  else
  {
    cout << "not less than";
  }
 
  return 0;
}
c_-_c_operator_overloading/logical_operator_overloading.txt · Last modified: 2020/07/15 10:30 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki