Arguments of the function have a type - the name of the class, how do you do? c++, VS13
-
In the commentaries, what's already done.
Create a class of double chemicals.
/ / Determine the overloaded function returning the maximum of two arguments.
/ The function is not a member of Double class.
The overburdened functions have arguments like int, double, Double.
/ / The body of overloaded functions shall be the same.
Is this the question of how to do 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 do we check the number of double or int?
-
Start 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);
}
Is that clear? :