Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/125.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 我得到一个错误:当我试图创建一个新的;“图像”;班_C++_Pointers_File Io_Constructor - Fatal编程技术网

C++ 我得到一个错误:当我试图创建一个新的;“图像”;班

C++ 我得到一个错误:当我试图创建一个新的;“图像”;班,c++,pointers,file-io,constructor,C++,Pointers,File Io,Constructor,我正试图在我的main中使用此方法读取文件。我有数据,我想从中提取,以创建一个新的图像对象。现在不太确定如何修复它 Image readFile(string fileName) { ifstream file; file.open(fileName); int rowCount; int column; if(file.is_open()){ file >> rowCount; file >> column; } int **row

我正试图在我的main中使用此方法读取文件。我有数据,我想从中提取,以创建一个新的图像对象。现在不太确定如何修复它

Image readFile(string fileName) {
ifstream file;
file.open(fileName);
int rowCount;
int column;
if(file.is_open()){

        file >> rowCount;
        file >> column;

}
int **row = new int*[rowCount];
Image i(**row, column); //The debugger stops here and gives the error!!!!!!!!
file.close();
return i;
}

这是图像对象的构造函数

Image::Image(int R = 0, int C = 0) {
if(R < 1 || C < 1) {
    *row = new int[10];
    column = new int[10];
} else {
*row = new int[R];
column = new int[C];
}
Image::Image(int R=0,int C=0){
if(R<1 | C<1){
*行=新整数[10];
列=新整数[10];
}否则{
*行=新整数[R];
列=新整数[C];
}

}

您没有为
*行
分配内存。我想我已经为int**row=new int*[rowCount]分配了内存;为
分配内存的。现在,您所拥有的只是
rowCount
未初始化的指针。为什么在readFile和构造函数中有一个名为row的东西?它们是同一个东西吗?另外:构造函数被声明为接收两个整数。您传递它**行,这是您从未初始化过的,因此第一个参数得到一些未定义的值。