Bertolt Hoover
Bertolt Hoover

Reputation: 71

C++ Type Identifier

Okay, so, if I do this in a C++ header function:

#include <iostream>
#include <string>
using namespace std;
// Prerequisites ^
int main(){
    int io_print([Here's what I need help with]){};
};

I know the code example was completely syntax wrong, but what I need help with is trying to use a type which allows integer, float and string. So I can simply do io_print(40) and io_print("Hi"). I've tried this and simply can't find any type that allows this, if anyone by any chance knows the answer then please reply.

I'm doing this as I want to redefine functions. Please don't ask why.

Upvotes: 3

Views: 542

Answers (1)

Brian Bi
Brian Bi

Reputation: 119034

template <typename T>
void io_print(const T& x) {
    cout << x;
}

Upvotes: 6

Related Questions