I wrote the following piece of code on codepad but I do not understand how/why it should compile.
#include<iostream>
using namespace std;
typedef double dObject;
typedef int iObject;
typedef void (*swapfuncptr)(dObject, dObject);
void swap(dObject a,dObject b) {
cout << a << " " << b << endl;
dObject tmp;
tmp = a;
a = b;
b = tmp;
cout << a << " " << b << endl;
}
int main() {
double a = 7.5, b = 5.3;
swapfuncptr swapptr1;
swapptr1 = &swap;
swapptr1(a, b);
int c = 3, d = 2;
swapfuncptr swapptr2;
swapptr2 = &swap;
swapptr2(c, d);
swapfuncptr swapptr3;
swapptr3 = &swap;
swapptr3('r', 'd');
return 0;
}
So dobject is only for doubles for the functions with integer parameters also work. I do not get how this works.
Can someone please explain.
Thanks
S
intis implicitly convertable todouble. Creating atypedeffordoubledoes not change that.