Skip to content

Instantly share code, notes, and snippets.

@ddrone
Created April 1, 2013 19:59
Show Gist options
  • Select an option

  • Save ddrone/5287301 to your computer and use it in GitHub Desktop.

Select an option

Save ddrone/5287301 to your computer and use it in GitHub Desktop.
Operator overriding in C++
#include <iostream>
#include <string>
using namespace std;
class A
{
public:
virtual void operator-(const A& other) const;
};
void A::operator-(const A& other) const {
cout << "Hello from A::operator-" << endl;
return;
}
class B : public A
{
public:
virtual void operator-(const B& other) const;
};
void B::operator-(const B& other) const {
cout << "Hello from B::operator-" << endl;
return;
}
int main()
{
A * a1 = new B();
B * b = new B();
(* a1) - (* a1);
(* b) - (* b);
delete a1;
delete b;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment