inheritance from a template base class

Hello,

I am writing the skeleton for an algorithm following the Strategy pattern presented in a plethora of c++ books, although my compiler does not like the way I am doing things.

If I compile the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;

template<typename T> 
class base{
protected:
	T _foo;
	T _bar;
protected:
	virtual void foo() = 0;
	virtual void bar() = 0;
public:
	void iteration(){
	foo();
	bar();
	};
};

class derived : public base<double>
{
public:
	derived(double foo, double bar){ 
	_foo=foo,
	_bar=bar;
}
	~derived();
protected:
	void foo() override {
		_foo++;
		cout << "calling overridden foo()" << endl;
	}
		void bar() override {
		_bar*=0.5;
		cout << "calling overridden bar()" << endl;
	}
};

int main (){
	derived *myClass = new derived(11,13);
	myClass->iteration();
	delete myClass;
	return 0;
}


I get as result:
1
2
3
4
Undefined symbols for architecture x86_64:
  "__ZN7derivedD1Ev", referenced from:
      _main in icpcMBZo0b.o
ld: symbol(s) not found for architecture x86_64

which is unexpected as all works if I specify the type T in the base class.
Do you actually define a destructor for the derived class anywhere?
Non I dont, and that solves my issue.
Topic archived. No new replies allowed.