我有一个类定义为这样:如何初始化二维数组作为类变量?
#include <stdio.h>
#pragma warning(disable:4996)
#define MAX_ROW 10
#define MAX_COLUMN 40
class VideoSim
{
private:
char video[MAX_ROW][MAX_COLUMN];
int currentRow;
int currentColumn;
public:
VideoSim::VideoSim(void);
VideoSim::~VideoSim(void);
void clearScreen(void);
int setCursorPosition(int row, int column);
};
我也有包含这些方法,因为这样我的.cpp文件:
#include "VideoSim.h"
VideoSim::VideoSim(void)
{
currentRow = 0;
currentColumn = 0;
video[MAX_ROW][MAX_COLUMN] = { 0 };
}
VideoSim::~VideoSim(void)
{
printf("Dead Video \n");
}
void VideoSim::clearScreen(void)
{
int count = 0;
char *pVideo = video[count];
for (count = 0; count < (MAX_ROW * MAX_COLUMN); count++)
{
*(pVideo++) = ' ';
}
}
int VideoSim::setCursorPosition(int newRow, int newColumn)
{
if (newRow >= 0 && newRow <= MAX_ROW && newColumn >= 0 && newColumn <= MAX_COLUMN)
{
currentColumn = newColumn;
currentRow = newRow;
return 0;
}
else
{
return 1;
}
}
现在,这是哪里出了问题我在主要发生:
#include "VideoSim.h"
int main(void)
{
VideoSim v;
return 0;
}
程序创建一个名为v
的VideoSim对象,但然后崩溃......为什么发生这种情况的任何想法?
考虑'的std :: array'数组 –