【发布时间】:2019-10-13 16:20:03
【问题描述】:
让我们看看这样的代码:
// Return me Dword of int
dword t = GetValueTypeNo<int>();
//here trying to tell to GetValue that my template is int (since t is dword of int)
int test5 = myVector.GetValue<t>("test5");
当然,这种代码是行不通的,实际上是没用的。但是有可能做这样的事情吗?将dword 强制转换为int 之类的类型名称?
【问题讨论】:
-
你绝对可以实现一个函数模板
GetValueTypeNo,每个特化返回一些id和其他模板方法GetValue使用那个id没有任何问题。 -
@VTT 我只是尝试创建一个快速函数来比较 dword 并返回 typedef 或 typename(例如 int),看看是否可行,但似乎 GCC 并不喜欢它^^跨度>
-
为什么不使用
GetValue<int>?为什么需要一定程度的间接性?有什么限制? -
@Evg 我只是想知道是否可以做类似的事情。
-
如果
GetValueTypeNo可以标记为constexpr,那肯定是可以的。