template<typename K, typename V, int N>
class KVList
{
int m_size;
K m_key[N] = {};
V m_value[N] = {};
public:
KVList& add(const K&, const V&)
{
//Check if index is empty or null
//Add key value pair
}
}
大家好,
我正在创建一个具有 3 个模板参数的模板类。如上所述,我的问题是如何确定某些索引处的数组是否为 NULL 或没有用户定义的值。
目前将这些数据类型作为模板参数传递:
w4::KVList<std::string, double, 5> x;
w4::KVList<std::string, std::string, 5> y;
我在想也许类似于将类型转换为 bool 的东西可能会有所帮助,但我被卡住了。
如果出现 KVList
接受与上面指定的数据类型或类不同的数据类型或类,我如何检查索引是否具有空值?
最佳答案
I want to know whether or not the array index is not user-defined so I can add values at the index.
你可以添加第三个 C 风格的 bool
数组
bool isSet[N] = {};
并在设置/取消设置键和值时设置/取消设置值。
关于c++ - 如何判断未知类型数组的索引是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48735377/