function overloading with different type variables

Learning a programming language is hard enough without having to wrangle your computer into compiling and executing your code. From beginners to experts, the tips here will make life in C++ easier.
Post Reply
darknkreepy3#
Site Admin
Posts: 254
Joined: Tue Oct 27, 2009 9:33 pm

function overloading with different type variables

Post by darknkreepy3# »

Code: Select all

/*
function overloading by Kristoffe Brodeur.©2010 All rights reserved.
06-13-2010
*/
#include <iostream>

using namespace std;

/*
each function 'overLoader' is stored as a possible way to respond to a function call to it
the program senses the TYPE of the sent variable.  If there are multiple TYPES, it senses the TYPE and PATTERN
*/

void overLoader(int sentVal)
    {
	cout	<< "overLoader*****\n" << "[int] version determined by an int sent.\n"
			<< "int sentVal=" << sentVal << "\n\n";
	}

void overLoader(bool sentVal)
    {
	cout	<< "overLoader*****\n" << "[int] version determined by a bool sent.\n"
			<< "bool sentVal=" << sentVal << "\n\n";
	}
	
void overLoader(char sentVal)
    {
	cout	<< "overLoader*****\n" << "[int] version determined by a char sent.\n"
			<< "char sentVal=" << sentVal << "\n\n";
	}
	
void overLoader(double sentVal)
    {
	cout	<< "overLoader*****\n" << "[int] version determined by an double sent.\n"
			<< "doublr sentVal=" << sentVal << "\n\n";
	}
	
/*
multipleTest looks to see the pattern of data TYPE calling the function
int bool double
bool int int
char int double
etc...
*/

void multipleTest(int sentNum,bool sentB,double sentFl)
	{
	cout	<< "multipleTest called. This pattern is TYPE (int)(bool)(double).\n\n";
	}

void multipleTest(bool sentB,int sentNumA,int sentNumB)
	{
	cout	<< "multipleTest called. This pattern is TYPE (bool)(int)(int).\n\n";
	}
	
void multipleTest(char sentChar,int sentNumA,double sentFl)
	{
	cout	<< "multipleTest called. This pattern is TYPE (char)(int)(double).\n\n";
	}
	
//-----		

int main()
{
    overLoader(11);
    overLoader(11.111);
    overLoader('p');
    overLoader(false);
    
    cout	<< "#=============================================#\n\n";
    
    multipleTest(11,true,555.34);
    multipleTest(true,76,53);
    multipleTest('h',5,1027.22);
    
    system("PAUSE");
    return EXIT_SUCCESS;
}
Post Reply