【发布时间】:2010-02-04 21:34:45
【问题描述】:
我有这种类结构。
class Interface {
// ...
};
class Foo : public Interface {
// ...
};
template <class T>
class Container {
// ...
};
我还有其他一些 Bar 类的构造函数。
Bar(const Container<Interface> & bar){
// ...
}
当我以这种方式调用构造函数时,我得到一个“没有匹配函数”的错误。
Container<Foo> container ();
Bar * temp = new Bar(container);
怎么了?模板不是多态的吗?
【问题讨论】:
-
模板不是多态的。与在运行时绑定的多态对象不同,模板在编译时绑定。
-
我认为这个其他答案可能会有很大帮助:stackoverflow.com/a/639276/6291795
-
我认为这个其他答案会很有帮助,stackoverflow.com/a/639276/6291795
标签: c++ templates polymorphism