Answer the question
In order to leave comments, you need to log in
Is the return type of a function taken into account when deciding which version of an overloaded function to use?
Hello, I am reading Herbert Schildt's Beginner's Guide.
There is such an example:
#include <iostream>
using namespace std;
void f(int x);
void f(short x);
void f(double x);
int main() {
int i = 10;
double d = 10.1;
short s = 99;
float r = 11.5F;
f(i);
f(d);
f(s);
f(r);
return 0;
}
void f(int x) {
cout << "В функции f(int): " << x << "\n";
}
void f(short x) {
cout << "В функции f(short): " << x << "\n";
}
void f(double x) {
cout << "В функции f(double): " << x << "\n";
}
Answer the question
In order to leave comments, you need to log in
C++ has implicit type casting. What function to call if exactly the same prototype does not exist?
float foo() { ... };
double foo(){ ... };
int bar()
{
int k=foo(); ///?????
...
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question