Total members 11890 |It is currently Sat Apr 20, 2024 6:43 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





Function overloading in C++
cpp code
#include <iostream>
#include <string>

using namespace std;

void fred(int a)
{
cout << "fred the first, " << a << endl;
}

void fred(int a, string b)
{
cout << "I am the second fred: " << a << " " << b << endl;
}

void fred(string c, string d = "ding!")
{
cout << "Lo, I am fred tertiary. " << c << " " << d << endl;
}

int main()
{
fred(17);
fred("this");
fred(24, "hours");
fred("some", "day");
}


C++ function overloading is much like Java's. Overloaded functions must differ by parameter type; differences in return type won't help. Default parameters provide an additional wrinkle, since a function with default parameters essentially counts as several overloaded functions, one for each signature with which it can be called.

Which of the following may be added?

cpp code
int fred(int x, string y);

int fred(double d);

double fred(string z, int q);

void fred(string cc);

int fred(int m, double d = 0.0);




_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 95
Have thanks: 2 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Function Overloading
 overloading << and >>     -  
 What is Operator Overloading? !!!     -  
 operator overloading     -  
 unary operator overloading     -  
 Operator overloading easy code     -  
 php function     -  
 The isset() Function     -  
 Function Recursion     -  
 finalize() function     -  
 srand function example     -  



Topic Tags

C++ OOP
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com