可以获取对象的静态类型吗?
can one get the static type of an object?
我觉得这应该是显而易见的,但我想我今天很生气。
如何让编译器为我提供事物的静态类型?
前任:
auto it = m_security_look_aside.find(strPath);
if (it == m_security_look_aside.end())
it = m_security_look_aside.insert(it, TYPE_OF(m_security_look_aside)::value_type(strPath, InternalIsLicensed(strPath)));
m_security_look_aside
是一个std::unordered_map<std::string, bool>
. std::unordered_map<std::string, bool>
有一个value_type
类型定义。
我可以使用std::unordered_map<std::string, bool>::value_type(key,value)
来构造一个属于这个无序映射的对。 但是,如何从实例转到其静态类型呢?
使用 decltype(m_security_look_aside)::value_type
- 即 decltype(m_security_look_aside)
可用于表示实例变量的类型。
但你在这里真的不需要它。相反,你可以做
it = m_security_look_aside.emplace_hint(it, strPath, InternalIsLicensed(strPath));
这"置换"(就地构造)正确value_type
的对象,使用参数(在初始"提示"迭代器之后)作为value_type
的构造函数参数。
相关文章:
- 非类类型表达式的静态类型与动态类型之间的差异
- (2 问题)"类"类型重新定义(即使 #pragma 一次),以及静态函数内的静态成员对象初始化?
- 初始化在类类型 #define 中定义的非静态成员数组,不带默认 ctor
- 初始化与类类型相同的静态成员(静态初始化顺序问题)
- 我可以从静态基方法获取当前类类型 ID 吗?
- 模板静态功能模板类类型扣除
- 获取静态类功能的类类型
- 静态类模板成员:将"sizeof"应用于不完整类型无效
- 类类型的静态constexpr字段在g++中给出链接时间错误
- 如何创建一个编译时静态类类型,该类型初始化具有特定值的成员容器
- 访问.CPP中定义的某些静态变量,而其类类型也在.cpp中定义
- 通过显式转换函数初始化枚举类类型的静态constexpr类成员
- 为什么类类型的静态变量和全局变量是危险的
- 与正在定义的类类型相同的静态 constexpr 成员
- 当类类型未知时,指向非静态成员函数的函数指针
- 使用静态强制转换时,强制转换为类类型或对象引用是否更有意义
- 初始化 C++ 中类中的非基元静态数据类型
- C++静态匿名类类型数据成员
- 使用派生类类型初始化模板类的静态数组
- 为什么静态类类型函数返回零