错误:'test'的外线定义与'B< dim>'中的任何声明都不匹配 [英] error: out-of-line definition of 'test' does not match any declaration in 'B<dim>'

查看:397
本文介绍了错误:'test'的外线定义与'B< dim>'中的任何声明都不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题就是杀了我!!我不知道下面的代码有什么问题。我应该能够实现从超类继承的函数,不应该吗?但我得到错误:'test'的外线定义与'B< dim>'中的任何声明都不匹配

I have a small problem that is killing me!! I don't know what seems to be wrong with the below code. I should be able to implement the function that is inherited from the super class, shouldn't I? but I get 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;
}

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

I am on a Mac using clang (Apple LLVM version 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;
}

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

You still need to define the function declared the class declaration.

这篇关于错误:'test'的外线定义与'B&lt; dim&gt;'中的任何声明都不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆