Let's say I want to create a function that cout passes a value, but I donβt know if it is int or string , or ....
cout
int
string
So something like:
void print(info) { cout << info; } print(5); print("text");
You can do this with a function template:
template <typename T> void print( const T& info) { std::cout << info ; }
One option is to use a function template.
template<typename Arg> void print(const Arg& arg) { std::cout << arg; }
We could use a template to complete it.
template <typename T> void print(const T& t) { std::cout << t <<std::endl; } int main() { print(12); print("123456"); }
Source: https://habr.com/ru/post/1490825/More articles:How to use Pipeline and Web Deploy Web Publishing (MSDEPLOY) to publish a console application? - console-applicationHow to distinguish class LineSegment from Line? - c ++Select with subquery to avoid starting more than once? - sqlHow to transfer real-time data between Java and C ++ code? - javaHow to increase the value on the map using Apex? - incrementFailed to update jQuery mCustomScrollbar - jqueryRemove orphaned sys.service_queue - sql-serverhttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1490828/trying-to-get-higher-order-functions-to-work-in-powershell&usg=ALkJrhgF5IjszpD9Y1C2etkebopEml66gQbefore (: each) vs before before - ruby-on-railsTStringHelper does not return correct results - delphiAll Articles