Reputation:
I'm trying to extend this class
template <class T> class dynamic_array
This does not work
class merge_sort : public dynamic_array
What is the proper way to extend the class?
Upvotes: 0
Views: 87
Reputation: 81349
You have to provide an argument for the template. If you want to use a fixed argument, say int
, then you would do:
class merge_sort : public dynamic_array< int >
If you instead want to keep the extended class as generic, you would do:
template< class T >
class merge_sort : public dynamic_array< T >
Note that merge sort is an algorithm, and as such it would be better off as a free function than as an object. According to OOP, you should ask is merge_sort
a dynamic_array
? For me the answer sounds as no, so I would do this instead:
template< class T >
void merge_sort( dynamic_array< T >& array ){ ... }
Upvotes: 4
Reputation: 25495
template<class T>
class merge_sort : public dynamic_array<T>
The template Arguments have to be specified to the base class you can however drive form a fully qualifed base class.
class merge_sort : public dynamic_array<int>
Upvotes: 1