错误:'test'的外联定义与'B<dim>'中的任何声明都不匹配
error: out-of-line definition of 'test' does not match any declaration in 'B<dim>'
我有个小问题快把我折磨死了!我不知道下面的代码似乎有什么问题。我应该能够实现从超类继承的功能,不是吗?但我得到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 version 5.1)。
Try
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;
}
您仍然需要定义类声明中声明的函数
问题是您试图在类b的类定义之外定义功能测试。您必须首先在类
中声明它template <int dim>
class B : public A <dim>
{
double test() const;
};
相关文章:
- EASTL矢量<向量<int>>连续的
- 在 C 中对 2 Dim 数组进行排序
- C - 创建矢量&lt; vector&lt; double&gt;&gt;矩阵具有分配而不是inizializ
- C 字符串比较“祝您好运”&gt;“再见”
- 为什么将此对向量&lt; map&lt; int,int&gt;&gt;中的地图进行更新.失败
- C++ 哪些列在 2 dim 数组中的每一行都有 1
- C :对矢量进行排序&lt; struct&gt;(结构有2个整数)基于结构的整数之一
- C 操作员&gt;&gt;与突变器过载
- 明确的专业化“ CheckIntmap&lt;&gt;”实例化
- 是否需要使用 - &gt;运算符在C 中调用成员函数时
- 什么是模板&lt;&gt;inline bla bla
- 编辑C Qlist&lt; object*&gt; gt;QML代码和一些QML警告中的模型
- eigen :: llt&lt;eigen :: matrixxd&gt;具有不完整的类型
- 错误,包括&lt; ctype&gt;在原子上使用C 11
- 错误c++visual studio c2227左侧'->;Init';必须指向类/结构/联合/泛型类型
- std::vector<;uint8_t>;当C++11/14启用时,手动复制而不是调用memcpy
- ``这个''不能用this-&gt;指针变量
- 如何加入向量&lt; int&gt;到C 中的单个INT
- C 2 DIM数组新获得0
- 是std :: set&lt; std :: future&gt;不可能存在