小编use*_*886的帖子

模板参数作为函数未命名参数

这个问题继续 非静态数据成员类推导

这是未命名的参数函数,我用它来返回std::string数据类型的表示

struct Boo {};
struct Foo {};

std::string class2str(const double) { return "Floating"; };
std::string class2str(const int) { return "Fixed Point"; };
std::string class2str(const Foo) { return "Class Foo"; };
std::string class2str(const Boo) { return "Class Boo"; };

int main(int argc, char* argv[]) 
{
    int    x_a;
    double x_b;
    Foo    F;
    Boo    B;
    std::cout << "x_a     :" << class2str(x_a) << std::endl;
    std::cout << "x_b     :" << class2str(x_b) << std::endl;
    std::cout << "Foo     :" << class2str(F) << std::endl; …
Run Code Online (Sandbox Code Playgroud)

c++ templates class function-templates c++17

4
推荐指数
1
解决办法
128
查看次数

标签 统计

c++ ×1

c++17 ×1

class ×1

function-templates ×1

templates ×1