c++ - 错误 : out-of-line definition of 'test' does not match any declaration in 'B<dim>'

标签 c++ macos templates inheritance virtual

我有一个小问题让我很烦!!我不知道下面的代码似乎有什么问题。我应该能够实现从父类(super class)继承的功能,不是吗?但我得到 error: out-of-line definition of 'test' does not match any declaration in 'B<dim>'

template <int dim>
class A 
{
public:
  virtual double test() const ;
};

template <int dim>
class B : public A <dim>
{
};

template <int dim>
double B<dim>::test () const
{
  return 0;
}

我在 Mac 上使用 clang(Apple LLVM 5.1 版)。

最佳答案

尝试

template <int dim>
class B : public A <dim>
{
public:
     virtual double test () const;
};

// Function definition
template <int dim>
double B<dim>::test () const
{
  return 0;
}

您仍然需要定义声明类声明的函数。

关于c++ - 错误 : out-of-line definition of 'test' does not match any declaration in 'B<dim>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22579666/

相关文章:

macos - 如果我将 Haskell Platform (2013.2.0.0) 与 GHC (7.6.3) 一起使用,是否可以安装 Xcode 5?

c++ - 如何在golang中实现c++ template<T>

c++ - 从 C++ 调用 Apache-FOP

c++ - GDI+图像缩放问题

python - 如何使用 mac OSX 将 python 脚本注册为 Web 浏览器

javascript - 自动更新主干下划线模板

templates - Template repeat inside template repeat - 获取所有项目名称

c++ - 使用 Boost.Geometry 时出现 "invalid operands to binary expression"?

c++ - 如何将 3d 模型渲染为 directshow 虚拟相机输出

python - 升级权限被拒绝 : how to upgrade pip on Mac OS X?