C ++ cannot create an abstract class

I am new to C ++. Could you help me get rid of the errors:

error C2259: "MinHeap": cannot create an abstract class

IntelliSense: return type is not identical and not covariant with return type "const int &" of overridden function of virtual functions

template <class T> class DataStructure { public: virtual ~DataStructure () {} virtual bool IsEmpty () const = 0; virtual void Push(const T&) = 0; virtual const T& Top() const = 0; virtual void Pop () = 0; }; class MinHeap : public DataStructure<int> { private: std::vector<int> A; public: bool IsEmpty() const { .. } int Top() const { .. } void Push(int item) { ... } void Pop() { .. } }; 
+4
source share
2 answers

The problem is const T& Top() vs. int Top() . The latter is different from the first and, therefore, is not an override. Instead, it hides the function of the base class. You need to return exactly the same as in the base class version: const int& Top() const .
The same problem exists for Push() , BTW.

+6
source

try

 class MinHeap : public DataStructure<int> { private: std::vector<int> A; public: bool IsEmpty() const { .. } const int& Top() const { .. } void Push(const int& item) { ... } void Pop() { .. } }; 

Note that instead of int , const int& for Top and Push

+2
source

All Articles