ex6-1.cpp - Example 6-1 Function overloading - non-exact matches

// File: ex6-1.cpp - function overloading

#include <iostream>
using namespace std;

class X
{
public:
	X(int) {}
};

void funk(int) { cout << "funk(int) called\n"; }
void funk(const double&) { cout << "funk(const double&) called\n"; }

void gunk(double&) { cout << "gunk(double&) called\n"; }

void hunk(double) { cout << "hunk(double) called\n"; } 

void junk(X) { cout << "junk(X) called\n"; } 


int main()
{
	double d;
	const double cd = 7.5;
	int i = 25;
	short s = 6;
	long l = 123456789;
	float f = 2.65f;			// note: use of float suffix

	funk(7);	// exact match
	funk(i);	// exact match
	funk(d);	// trivial conversion
	funk(s);	// promotion
	funk(cd);	// exact match
//	funk(l);	error: ambiguity
	funk(f);	// conversion
//	gunk(cd);	error cannot convert const to non-const
//	gunk(i);	error cannot convert int to double&
	hunk(i);	// conversion
	junk(i);	// user-defined conversion

	return 0;
}



CIS27: Programming in C++    Instructor: Joe Bentley