是否可以在不知道模板类型的情况下指向模板化类

Is it possible to point to templated class without knowing the template type?

本文关键字:情况下 类型 不知道 是否      更新时间:2023-10-16

我想做这样的事情,但我不确定这是否可能。我在谷歌上找不到任何信息。

template <typename T>
class Container {
public:
  T *ptr;
};
class Other {
private:
  Container *container_ref;
}

感谢您的帮助。

它不是,但如果你负责Container那么你可以让它从非模板化的基类继承,并保留一个指向它的指针。

No.模板不是类,而是有关如何构建类的说明。如果没有模板参数(显式或隐含(,它就不完整。

你可以看看 Boost::any 来解决问题。

相关文章: