Hi can anyone help? I need to print the top element of a stack of Objects (in this case points) and i am unable to find a solution online. I have attempted changing the datatype of top or straight up calling pointStack.top() in the cout but i have had no luck. Note. I have not included the Pop function as error C2679 is the issue
#include <iostream>
#include <stack>
#include "point.h"
using namespace std;
int main(){
stack<Point> pointStack;
Point p;
int i;
int counter = 0;
for (i = 0; i < 10; i++){
p.pCreate();
Point p1(p.getXPos(), p.getYPos());
pointStack.push(p1);
counter++;
}
while (!pointStack.empty()){
Point top = pointStack.top();
cout << top; // error C2679
cout << pointStack.top(); // also error C2679
}
system("PAUSE");
return 0;
}
#ifndef __Point__
#define __Point__
using namespace std;
class Point{
private:
int x, y;
public:
Point();
Point(int x, int y);
int getYPos(){ return y; }
int getXPos(){ return x; }
void pCreate();
};
#endif
Point::Point(){
x = 0, y = 0;
}
Point::Point(int a, int b){
x = a;
y = b;
}
void Point::pCreate(){
x = -50 + rand() % 100;
y = -50 + rand() % 100;
}