For a class I have to use a stack. From what I can tell I create a stack with
#include <stack>
class c1
{
stack<Point> openstack;
};
Point is a class I created that has an x and y int value to store points for using in simple 2D graphics. The problem I’m having is that if I do
Point p = openstack.pop();
I get an error: “No suitable consturtor exists to convert from void to Point”
Point has a set function that takes a point and will use the passed point to store the x and y values but this does not work either.
Point p;
p.set(openstack.pop()); // does not work
Can someone tell me what I am doing wrong? If you need info please ask – I can give more if needed.
pop()doesn’t return a value. It just removes the top value. It’s declared like this:To get the top value you need to call
top(). After that you can callpop().There are a couple reasons why
pop()does not return the value popped.