In the comments - what is already done

Create a class of real numbers Double.

// Define an overloaded function that returns the maximum of two arguments.

// The function is not a member of the Double class.

Overloaded functions have arguments of type int, double, Double.

// The body of overloaded functions should be the same.

Here is the question of how to make a Double?

#include "stdafx.h" class Double{ }; int func(int num1, int num2){ int value; if (num1 > num2) value = num1; if (num1 < num2) value = num2; return value; } double func(double num1, double num2){ double value; if (num1 > num2) value = num1; if (num1 < num2) value = num2; return value; } int _tmain(int argc, _TCHAR* argv[]) { return 0; } 

By the way, how to check the input number double or int?

  • do you need the most? then I suggest to write max(num1,num2) , if you need T func(const T num1, const T num2) { if (num1 < num2) return num1; return num2; } T func(const T num1, const T num2) { if (num1 < num2) return num1; return num2; } T func(const T num1, const T num2) { if (num1 < num2) return num1; return num2; } For your Double class, you can write pair<double,double> and so on. - pavel
  • How-how, define operator< for your Double to start. Learn how to do this correctly. - VladD
  • First and foremost, you are not ready: Create a class of real numbers Double . As soon as you create it, it will immediately become clear what's next. Just in case, creating a class does not mean simply typing class Double ... - Harry
  • @Harry says the same in the comments that what is ready in the comments, and I don’t know how it should look like for this task and how to use it - Vyacheslav
  • Sketched the beginning. Further cope? - Harry

1 answer 1

First create a class. Like that.

 class Double { public: Double(double val = 0.0):val(val){} Double(const Double&) = default; ~Double() = default; Double& operator= (const Double&) = default; operator double() const { return val; } private: double val; }; bool operator < (const Double& x, const Double& y) { return static_cast<double>(x) < static_cast<double>(y); } 

Then everything is clear? :)

  • Now I will try, I do not quite understand how the operator works, what does it return? true or false? I simply didn’t teach with ++ and therefore even elementary things are not clear, I apologize in advance for stupid questions - Vyacheslav
  • It returns true if x < y , and false otherwise. - Harry