Let's say I want to create a function that cout
s the value I pass it, but I don't know whether it is an int
, or a string
, or….
So something like:
void print(info) {
cout << info;
}
print(5);
print("text");
You can do it with a function template:
template <typename T>
void print( const T& info)
{
std::cout << info ;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With