Does anyone know why std::queue, std::stack, and std::priority_queue don\'t provide a clear() member function? I have to fake one like this:
st
You CAN clear queues (and std::stack and priority_queue), as long as you inherit from it. The container is intentionally left protected to allow this.
#include
using namespace std;
class clearable_queue : public queue
{
public:
void clear()
{
// the container 'c' in queues is intentionally left protected
c.clear();
}
};
int main(int argc, char** argv)
{
clearable_queue a;
a.clear();
}