I'm allocating dynamic memory in my class as a private: variable
Then in the constructor I'm trying to initialize the array.
public
Display(int Width, int Height) {
nScreenHeight = Height;
nScreenWidth = Width;
DWORD dwBytesWritten = 0;
for (int i = 0; i < (nScreenWidth*nScreenHeight); i++) screen[i] = L'';
SetConsoleActiveScreenBuffer(hConsole);
}
private:
int nScreenWidth;
int nScreenHeight;
wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];
If I try run the program an Exception Unhanded in thrown.
Unhandled exception thrown: write access violation. this->screen was 0x2096112.
While trying to initialize the buffer screen with L' '
wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];nScreenHeight and nScreenWidth are not initailized when this executes. Initializescreenin your constructor.wchar_t *screen = new wchar_t[nScreenWidth*nScreenHeight];doesn't do what you think it does. I wonder if this even compiles. Putscreen = new wchar_t[nScreenWidth*nScreenHeight]to your constructor initializer list at least.L''actually evaluate as? I'm surprised that even compiles.L"", (a pointer to a null-terminated wchar_t string) notL''.L''should result in a compiler error:error: empty character constant.