#include<iostream>
using namespace std;
class Swap {
public:
virtual void swap(int &a, int &b) = 0;
};
class SwapNumbers : public Swap {
public:
void swap(int &a, int &b) {
int temp = a;
a = b;
b = temp;
}
};
int main()
{
int x = 10;
int y = 20;
cout << "Before swapping: x = " << x << ", y = " << y << endl;
Swap *ptr;
SwapNumbers s;
ptr = &s;
ptr->swap(x, y);
cout << "After swapping: x = " << x << ", y = " << y << endl;
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: