-1

Basically I need to overload the operators for boolean and double. For boolean I need to overload &&, ||, and << For double I need to overload: + - * / ^ && || << Here is the boolean.h file

#ifndef BOOLEAN_H
#define BOOLEAN_H

#include "iostream";

using namespace std;

class Boolean {
public:
    Boolean();
    Boolean(const Boolean& orig);
    virtual ~Boolean();
    //overload the &&, ||, and << operators here.
private:

};

#endif

Here is the double.h file

#ifndef DOUBLE_H
#define DOUBLE_H

class Double {
public:
    Double();
    Double(const Double& orig);
    virtual ~Double();
private:

};

#endif
vallentin
  • 23,478
  • 6
  • 59
  • 81
user3404082
  • 99
  • 1
  • 1
  • 3
  • What is it that you want people to do for you exactly? And why are you re-implementing basic types...? – Matti Virkkunen Apr 14 '14 at 01:01
  • Preprocessor directives shouldn't end with semicolons. Anyway, [operator overloading](http://stackoverflow.com/questions/4421706/operator-overloading). – chris Apr 14 '14 at 01:05
  • 2
    Warning: Overloaded `&&` and `||` operators will not have the "short-circuit" behavior programmers are used to. – aschepler Apr 14 '14 at 01:20

1 Answers1

0
   virtual ~Boolean();
   friend Boolean operator&&(const Boolean& lhs, const Boolean& rhs)
   {
       // assuming bool truth_ member... adjust as necessary
       return lhs.truth_ && lhs.truth_;
   }
   //similar for ||
   friend std::ostream& operator<<(std::ostream& os, const Boolean& b)
   {
       return os << (b.truth_ ? "True" : "False");
   }

private:

Same kind of thing for the Double operators.

Alternatively, you could define these outside the class, which is arguably cleaner if they don't need friendship:

   Boolean operator&&(const Boolean& lhs, const Boolean& rhs)
   {
       // assuming bool is_true() member function... adjust as necessary
       return lhs.is_true() && lhs.is_true();
   }
Tony Delroy
  • 102,968
  • 15
  • 177
  • 252