As Richard had already pointed out, a data type is needed that fits all passed parameters. As usual you can define such a type yourself, if nothing fits in the standard. My suggestion here would be a class multitype, which provides an overload for all needed parameter data types and can also restore these data types as ostream. The call would then look as desired:
void printValues(multitype val1, multitype val2)
{
cout << val1 << " " << val2 << endl;
}
int main()
{
printValues(10, 20);
printValues(30, "Hello");
printValues(2.5, 7.5);
return 0;
}
Since the multitype data type does not yet exist, it must first be defined. This could look like this, for example:
class multitype {
public:
multitype(int d);
multitype(double d);
multitype(std::string mts) :_s(mts) { _typ = T_STRING; };
multitype(const char* mts):_s(mts) { _typ = T_STRING; };
enum DDTYPE { T_NONE, T_INT, T_DOUBLE, T_STRING };
DDTYPE getype() { return _typ; };
std::string getdata_s() { return _s; };
friend ostream& operator<<(ostream&, multitype&);
private:
DDTYPE _typ;
int _d;
double _dd;
string _s;
};
The rest is housework and I like to leave that to the questioner. I still briefly give some outlines here:
multitype::multitype(int d) { };
multitype::multitype(double d) { };
ostream& operator<<(ostream& os, multitype& mt) { return os; };