#include <iostream> template <typename T> auto f1(const T& x) { std::cout << x << std::endl; }; auto f2 = [](const auto& x){ std::cout << x << std::endl; }; int main(int argc, char** argv) { int x1 = 1; double x2 = 1.0; char x3 = '1'; std::string x4 = "1"; f1(x1); f1(x2); f1(x3); f1(x4); f2(x1); f2(x2); f2(x3); f2(x4); }
标签:std,f1,const,函数,C++,模板 From: https://www.cnblogs.com/qiandeheng/p/17387815.html