Linked Questions

Popular Questions

The below code results in the following compile error:

error: no matching member function for call to 'push' 

The issue goes away if I remove the const for the ptr parameter within func. So this seems to mean that you can't push a constant pointer into a stack. Why is this the case? It also appears to give the same error if I try to push it into std::queue, and I suspect other containers as well.

#include <iostream>
#include <stack>

void func(const int *&ptr)
   std::stack<int *> st;

int main(int argc, char const *argv[])
   int i = 2;
   auto ptr = &i;

Related Questions