“让您知道Kova =将这段用土耳其语写成的代码放在桶里。”
#include<iostream>
#include<vector>
using namespace std;
class Kova
{
public:
void KovaCizdir(const char *dizi[6][6])
{
dizi[0][0] = "";
dizi[0][1] = "";
dizi[0][2] = ".";
dizi[0][3] = "|";
dizi[0][4] = ".";
dizi[0][5] = "";
dizi[0][6] = "";
dizi[1][0] = "";
dizi[1][1] = ".";
dizi[1][2] = "";
dizi[1][3] = "";
dizi[1][4] = "";
dizi[1][5] = ".";
dizi[1][6] = "";
dizi[2][0] = ".";
dizi[2][1] = "";
dizi[2][2] = "";
dizi[2][3] = "";
dizi[2][4] = "";
dizi[2][5] = "";
dizi[2][6] = ".";
dizi[3][0] = "#";
dizi[3][1] = "";
dizi[3][2] = "";
dizi[3][3] = "";
dizi[3][4] = "";
dizi[3][5] = "";
dizi[3][6] = "#";
dizi[4][0] = "#";
dizi[4][1] = "";
dizi[4][2] = "";
dizi[4][3] = "-";
dizi[4][4] = "";
dizi[4][5] = "";
dizi[4][6] = "#";
dizi[5][0] = "#";
dizi[5][1] = "";
dizi[5][2] = "";
dizi[5][3] = "";
dizi[5][4] = "";
dizi[5][5] = "";
dizi[5][6] = "#";
dizi[6][0] = "#";
dizi[6][2] = "#";
dizi[6][3] = "#";
dizi[6][4] = "#";
dizi[6][5] = "#";
dizi[6][6] = "#";
};
void KovaOlustur(int kovaSayisi)
{
for (int t = 0; t < kovaSayisi; t++)
{
char *Kovalar[6];
for (int i = 0; i < 7; i++)
{
Kovalar[i] = new char[6];
}
}
};
};
int main()
{
int kovaSayisi;
cout << "Kova Sayisi : ";
cin >> kovaSayisi;
Kova *kova = new Kova();
kova->KovaOlustur(kovaSayisi);
kova->KovaCizdir(*Kovalar[6][6]);
}
标识符“ Kovalar”是未定义的错误 我如何解决这个问题,我是使用指针的新手。 我正在尝试使用指针制作存储桶形状,以后用户可以更改存储桶的字段并更改其编号。 它可能包含许多我想都知道的逻辑错误。
答案 0 :(得分:0)
在您的代码中-Kovalar是KovaOlustur
方法的局部变量,因此外面的世界看不到它。此外,您提供的代码中还有一些小缺陷,让我帮助您纠正它们:
#include<iostream>
#include<vector>
using namespace std;
class Kova
{
private:
char *Kovalar[6]; // make the Kovalar a member variable of the class
public:
Kova(int kovaSayisi) {
KovaOlustur( kovaSayisi);
// otherwise you can move the whole code of KovaOlustur code here like:
/* for (int t = 0; t < kovaSayisi; t++)
{
for (int i = 0; i < 7; i++)
{
Kovalar[i] = new char[6];
}
}*/
}
void KovaCizdir() // no parameters required, as the data is now a member variable
{
// anything in double quote "" is treated as a const char* in c/c++
// but you are trying to access the Kovalar with 2 indices which make that to be
// char - so change the double quotes "" to single quotes ''
Kovalar[0][0] = ' ';
Kovalar[0][1] = ' ';
Kovalar[0][2] = '.';
Kovalar[0][3] = '|';
Kovalar[0][4] = '.';
Kovalar[0][5] = ' ';
Kovalar[0][6] = ' ';
Kovalar[1][0] = ' ';
Kovalar[1][1] = '.';
Kovalar[1][2] = ' ';
Kovalar[1][3] = ' ';
Kovalar[1][4] = ' ';
Kovalar[1][5] = '.';
Kovalar[1][6] = ' ';
Kovalar[2][0] = '.';
Kovalar[2][1] = ' ';
Kovalar[2][2] = ' ';
Kovalar[2][3] = ' ';
Kovalar[2][4] = ' ';
Kovalar[2][5] = ' ';
Kovalar[2][6] = '.';
Kovalar[3][0] = '#';
Kovalar[3][1] = ' ';
Kovalar[3][2] = ' ';
Kovalar[3][3] = ' ';
Kovalar[3][4] = ' ';
Kovalar[3][5] = ' ';
Kovalar[3][6] = '#';
Kovalar[4][0] = '#';
Kovalar[4][1] = ' ';
Kovalar[4][2] = ' ';
Kovalar[4][3] = '-';
Kovalar[4][4] = ' ';
Kovalar[4][5] = ' ';
Kovalar[4][6] = '#';
Kovalar[5][0] = '#';
Kovalar[5][1] = ' ';
Kovalar[5][2] = ' ';
Kovalar[5][3] = ' ';
Kovalar[5][4] = ' ';
Kovalar[5][5] = ' ';
Kovalar[5][6] = '#';
Kovalar[6][0] = '#';
Kovalar[6][2] = '#';
Kovalar[6][3] = '#';
Kovalar[6][4] = '#';
Kovalar[6][5] = '#';
Kovalar[6][6] = '#';
// otherwise you can also write like this:
/*Kovalar[0] = " ./. ";
Kovalar[1] = " . . ";
Kovalar[2] = ". .";
Kovalar[3] = "# #";
Kovalar[4] = "# - #";
Kovalar[5] = "# #";
Kovalar[6] = "#######"; */
}
void KovaOlustur(int kovaSayisi)
{
for (int t = 0; t < kovaSayisi; t++)
{
for (int i = 0; i < 7; i++)
{
Kovalar[i] = new char[6];
}
}
}
};
int main()
{
int kovaSayisi;
cout << "Kova Sayisi : ";
cin >> kovaSayisi;
Kova *kova = new Kova(kovaSayisi); // here the variable kovaSayisi is not at all used, you can eliminate that
//kova->KovaOlustur(kovaSayisi); /* now no need of this call because this is done in the constructor itslef
kova->KovaCizdir(); // no need of passing the parameter, becuase the data is now a member of the class itself
}
我已提供内联注释,以帮助您理解,希望对您有所帮助并解决您的问题。
谢谢
Rajkumar