I have two classes Display and Snake. With the Display class I hols some functionality that involves creating buffer and etc. I'm trying to do something that seem logical to me but apparently not to the compiler
cSnake.h
class Snake
{
public:
Snake();
void printSnake();
~Snake();
private:
Display* display;
};
cSnake.cpp
Snake::Snake() {}
void Snake::printSnake() {
display->PrintCharecter(40, 15, L" Hello World ");
}
Snake::~Snake() {}
This is the Display class
Class Display{
public:
void CreateScreenBuffer();
void DisplayFrame();
void PrintCharecter(int x, int y LPCWSTR text);
private:
int nScreenWidth;
int nScreenHeight;
wchar_t *screen;
}
// The function that I try to call
void Display::PrintCharecter(int x, int y, LPCWSTR text) {
wsprintf(&screen[y* nScreenWidth + x], text); // exception is thrown here
}
Calling it in the main
Snake snake
snake.printSnake();
Then it throws unhanded exception that. Being NULL pointer. I bit confused here, which one the NULL pointer is it the function call or the array screen?