[Solved] Problem with pushing into stack with generic type [closed]


Your question misses important details and actually I shouldnt be writing this answer, but as you actually also didnt ask a question, I just do it.

This error message:

error: no matching function for call to ‘AlgoStack<State<std::pair<int, int>* >>::push(State<std::pair<int, int> >*&)’

tells us that there is an instantiation of AlgoStack with the template parameter being State<std::pair<int, int>*:

error: no matching function for call to ‘AlgoStack<State<std::pair<int, int>* > > ...
                                                   ^--------------------------^

and the compiler needs that to have a push accepting a State<std::pair<int, int> >*&:

error: [...]>>::push(State<std::pair<int, int> >*&)
                     ^---------------------------^

Now lets look at the template:

//Inculdes...
template <class T>
class AlgoStack : public DataManager<T>{
 private:
  stack<State<T>*> myQ;
 public:
  void push(State<T>* temp) override {
    myQ.push(temp);
  }

The instantiation mentioned in above error (AlgoStack<State<std::pair<int, int>* > >) has a

push( State< State<std::pair<int,int>* >* temp) 

but not the overload you are trying to call. I suppose there is one level of State too much and you can remove one of them.

solved Problem with pushing into stack with generic type [closed]