相关疑难解决方法(0)

强类型定义

有没有办法制作一个类型的完整副本,以便可以在模板推导上下文中区分它们?举个例子:

#include <iostream>

template <typename T>
struct test
{
    static int c()
    { 
        static int t = 0;
        return t++;
    }
};

typedef int handle;

int main()
{
    std::cout << test<int>::c() << std::endl;
    std::cout << test<handle>::c() << std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

由于typedef只为类型创建别名,因此打印0,1而不是所需的0,0.是否有解决方法?

c++ templates type-deduction

11
推荐指数
2
解决办法
8755
查看次数

标签 统计

c++ ×1

templates ×1

type-deduction ×1