C++関数リロード

3283 ワード

int、float、doubleの3種類のデータの絶対値を計算する関数を再ロードします.
#include
using namespace std;
int Abs(int x) { return x > 0 ? x : -x; }
float Abs(float x) { return x > 0 ? x : -x; }
double Abs(double x) { return x > 0 ? x : -x; }
void main() {
	cout << Abs(-9) << endl;
	cout << Abs(-9.9f) << endl;
	cout << Abs(-9.8) << endl;
}