Is it possible to specify multiple types for a function parameter?

Viewed 6384

It is possible in C++ define a function argument to be of more than one type?

#include <iostream>
using namespace std;

class A {
public:
   void  PrintA() { cout << "A" << endl;}
};

class B {
public:
   void  PrintB() { cout << "B" << endl;}
};

class C: public A, public B {
public:
   C(){;}
};

class D: public A, public B {
public:
   D(){;}
};

///
void __printall__(A*a, B*b){
   a->PrintA();
   b->PrintB();
}
#define printall(a) __printall__(a,a)
///

int main(int argc, char *argv[]){
   C c;
   D d;
   printall(&c);
   printall(&d);
}

I want to change the code between the comments with something not using macros. I would not force the pointers cast because I want to preserve the type safety. I would not even introduce another class between C/D and A/B because actually my class hierarchy is a bit more complex of that shown in the code, and it is not desirable to rebase all the class that derive from A or B

3 Answers
Related