【发布时间】:2016-03-15 08:32:46
【问题描述】:
此处已回答:How can an incomplete type be used as a template parameter to vector here? 在实例化模板组件时使用不完整类型作为模板参数可能会导致未定义的行为。但是,当我们只有指向具有不完整类型的模板组件的指针/引用作为参数时,该规则是否成立?这种情况下是否也会发生实例化?
例如:
// SomeAlgoInterface.hpp
#include <vector>
struct Result; // forward declaration
class SomeAlgoInterface
{
public:
virtual ~SomeAlgoInterface() = default;
public:
// the following line is definitely OK, ...
virtual void f1(const Result & result) = 0;
// ... but I'm not quite sure about the following one
virtual void f2(const std::vector<Result> & results) = 0;
};
换句话说,上面的代码是否有效?
【问题讨论】:
-
根据[temp.inst]/4中的例子,这个声明不会导致实例化
标签: c++ templates c++11 vector