GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Why is this code not working?

class Snake {
private:
	int snakex, snakey, foodx, foody, food = 0;
	enum Surf { stop = 0, Left, Right, up, down };
	Surf dir;

public:
	int tail;
	int tailx[200], taily[200];
	const int width = 20;
	const int height = 20;
	bool gameover;
	void Start();
	void set_input();
	void Grid();
	void build();

};


void Snake::Grid() {
	system("cls");
	for (int i = 0; i < width + 1; i++) {  
		cout << "_";
	}
	cout << endl;
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			if (j == 0) {
				cout << "|";
			}

		if (i == snakey && j == snakex) //placing head of snake
			cout << "O";
			else if (i == foody && j == foodx) //placing food 
				cout << "@";
			else {
				bool add = false;
				for (int k = 0; k < tail; k++) {

					if (tailx[k] == j && taily[k] == i) {
						cout << "o";
						add = true;
					}

				}
				if (!add) {
					cout << " ";
				}
			}

			if (j == width - 1)
				cout << "|";
		}
		cout << endl;
	}
	for (int i = 0; i < width / 2 + 1; i++) {
		cout << "--";
	}
	cout << endl;
	cout << "Food:" << food;
}
void Snake::build() {
	int prevx = tailx[0];
	int prevy = taily[0];
	tailx[0] = snakex;
	taily[0] = snakey;
	int prev2x, prev2y;
	for (int i = 1; i < tail; i++) {
		prev2x = tailx[i];
		prev2y = taily[i];
		tailx[i] = prevx;
		taily[i] = prevy;
		prevx = prev2x;
		prevy = prev2y;
	}
	switch (dir)
	{
	case Left:
		snakex--;
		break;
	case Right:
		snakex++;
		break;
	case up:
		snakey--;
		break;
	case down:
		snakey++;
		break;
	default:
		break;
	}
	/*if (snakex > width || snakex<0 || snakey>height || snakey < 0) {
	gameover = true;
	}*/
	if (snakex >= width) snakex = 0; else if (snakex < 0) snakex = width - 1;
	if (snakey >= height) snakey = 0; else if (snakey < 0) snakey = height - 1;
	for (int i = 0; i < tail; i++) {
		if (tailx[i] == snakex && taily[i] == snakey) {
			gameover = true;
		}
	}
	if (snakex == foodx && snakey == foody) {
		food += 1;
		foodx = rand() % width;
		foody = rand() % height;
		tail++;
	}
}
int main()
{
	Snake s;
	s.Start();
	while (!s.gameover) {
		s.Grid();
		s.set_input();
		s.build();
		Sleep(200);

	}
	return 0;
}

I have removed the function Start() and set_input() for time being.The small oh('o') in the function Grid() is not printed .But when I remove the class and OOP related stuff ,it gets printed.What could be the reason?

asked Feb 11 by anonymous
...