Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: out-of-line definition of 'test' does not match any declaration in '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;
}

I am on a Mac using clang (Apple LLVM version 5.1).

like image 380
Fahad Alrashed Avatar asked Mar 22 '14 15:03

Fahad Alrashed


2 Answers

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;
}

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

like image 80
πάντα ῥεῖ Avatar answered Sep 22 '22 03:09

πάντα ῥεῖ


The problem is that you are trying to define function test outside the class definition of class B. You have to declare it at first in the class

template <int dim>
class B : public A <dim>
{
   double test() const;
};
like image 21
Vlad from Moscow Avatar answered Sep 21 '22 03:09

Vlad from Moscow