Skip to content

Instantly share code, notes, and snippets.

@GianpaMX
Created April 12, 2013 14:54
Show Gist options
  • Save GianpaMX/5372612 to your computer and use it in GitHub Desktop.
Save GianpaMX/5372612 to your computer and use it in GitHub Desktop.
How to ovearload functions in C++ and PHP
#include <iostream>
#include <string>
using namespace std;
class A {
public:
void f(const string &arg1, const string &arg2) {
cout << arg1 << ", " << arg2 << endl;
}
};
class B : public A {
public:
void f(const string &arg1) {
A::f(arg1, "I'm B");
}
};
int main() {
A a;
a.f("Hello", "World");
B b;
b.f("foo");
return 0;
}
<?php
class A {
public function f() {
$args = func_get_args();
$arg1 = $args[0];
$arg2 = $args[1];
echo "$arg1, $arg2\n";
}
}
class B extends A {
public function f() {
$args = func_get_args();
$arg1 = $args[0];
parent::f($arg1, "I'm B");
}
}
$a = new A();
$a->f("Hello", "World");
$b = new B();
$b->f("foo");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment