" I have a little problem that kills me !! I don't know ...">

Error: the definition of "test" outside the line does not match the declaration in "B <dim>"

I have a little problem that kills me !! I don't know what seems wrong with the code below. I should be able to implement a function that is inherited from a superclass, right? 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 version).

+7
c ++ inheritance virtual templates macos
source share
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 by the class declaration.

+9
source share

The problem is that you are trying to define a function test outside the class definition of class B. First you must declare it in the class

 template <int dim> class B : public A <dim> { double test() const; }; 
+2
source share

All Articles