让我考虑一下,我有4个字节来描述一些实际的系统参数。假设可以将其解释为float,uint32_t和boolean。一起存储和处理此变量的主要思想。现在我使用一个类(非常简化的)具有的4个字节,函数数组float toFloat(),uint32_t toInt(),bool toBool()和参数ID(指定存储值类型)。所以我需要一个函数T getValue()来返回正确类型的值T。所以我的问题是:最正确的方法是什么?我应该使用模板,继承,其组合还是其他?
float toFloat()
uint32_t toInt()
bool toBool()
T getValue()
T
c++ inheritance templates data-storage
c++ ×1
data-storage ×1
inheritance ×1
templates ×1