是否可以在不知道模板类型的情况下指向模板化类
Is it possible to point to templated class without knowing the template type?
我想做这样的事情,但我不确定这是否可能。我在谷歌上找不到任何信息。
template <typename T>
class Container {
public:
T *ptr;
};
class Other {
private:
Container *container_ref;
}
感谢您的帮助。
它不是,但如果你负责Container
那么你可以让它从非模板化的基类继承,并保留一个指向它的指针。
No.模板不是类,而是有关如何构建类的说明。如果没有模板参数(显式或隐含(,它就不完整。
你可以看看 Boost::any 来解决问题。
相关文章:
- 为什么在这种情况下,bool 类型的输出等于 0?
- C++默认情况下,指针类型数组的元素是否保证初始化为 nullptr?
- 如何在没有实例的情况下获取非静态方法的类型?
- 如何在不破坏现有应用程序的情况下更改 API 中 stl 容器的数据类型?
- 是否可以在不使用 decltype 的情况下推断先前定义的 extern 变量的类型
- 在没有标识符的情况下如何读取复杂的C++类型声明?
- MSVC 在不知道类型的情况下评估上下文(和错误)
- 我们可以在不知道其真实类型的情况下将基类指针转换为派生类指针吗?
- 如何在不给它任何类型(如整数)的情况下定义某物?
- 为什么我不能在不进行任何转换的情况下将浮点数放入任何类型的 ptr 中?
- 将类型映射到整数值后,如何在给定整数值的情况下恢复类型?
- 如何在不违反类型别名规则的情况下解释消息负载?
- msgpack:在不知道类型的情况下解包自定义类
- 对于多态类型T,如何在没有类型T实例的情况下获得指向T的虚拟表的指针
- 在这种特殊情况下,我是否需要在共享内存中使用原子类型
- 为什么在以下情况下不需要为依赖类型使用typename
- 有没有办法在没有reinterpret_cast的情况下保存多种类型的指针?
- 如何定义可以在没有联合的情况下容纳uintptr_t或uint32_t的类型?
- 推荐的方法在不初始化值的情况下使数组类型为 std::unique_ptr?
- 为什么默认情况下C++类型不是常量?