0
What is the overloading functions
with examples
3 Antworten
+ 4
So C++ allows you to give your function more than one definition of itself.
Like this:
#include <iostream>
using namespace std;
class printData {
public:
void print(int w) {
cout << "This is an integer: " << w << endl;
}
void print(char* c) {
cout << "This is a character: " << c << endl;
}
};
int main(void) {
printData p;
p.print(5); // prints out --> This is an integer: 5
p.print("Hello, world!"); // prints out --> This is a character: Hello, world!
return 0;
}
+ 4
In object oriented programming you can overload a method ( function). I'ts usefull to create a consistent and clean semantic to build your application.
Example:
teacher.update(name)
teacher.update(age)
assuming that name is a string, and age is an integer
+ 1
thankx