숙제에 대한 도움이 필요합니다. 주차 시설 코드를 작성해야합니다. 그것을 작성하려면 힙과 다른 클래스 "Parkinggarage"를 통해 #define EMPTY "--------".
으로 작성된 클래스 "Parkbox
"의 인스턴스를 복사해야합니다. 따라서 내 코드는 입니다. Parkbox 정의 :클래스의 인스턴스를 C++의 char * 변수와 어떻게 비교할 수 있습니까?
class Parkbox{
char *license_plate; // car's license plate
public:
Parkbox(); //Default CTOR
Parkbox(char *); // CTOR
~Parkbox(); // DTOR
void show();
};
and ParkingGarage:
class ParkingGarage{
Parkbox ***p2parkboxes;
주문 나의 ctor에 또는 ParkingGarage는 힙에 Parkbox 인스턴스를 만들려면 다음
ParkingGarage::ParkingGarage(const int rw,const int clm, const int plns){
p2parkboxes = new Parkbox **[plns];//points to the floors and make the arraq of p2p same size as number as floors
for(int p=0;p<plns;p++){
p2parkboxes[p]= new Parkbox *[plns];//for each Plane creats an array of pointer that is same with the num of rows
for(int r=0;r<rw;r++)
p2parkboxes[p][r]= new Parkbox [clm];
}
}
void ParkingGarage::find_next_free_parking_position()
{
for(int f=0;f<dimensions_of_parkhouse[0];f++){
for(int r=0;r<dimensions_of_parkhouse[1];r++){
for (int c=0;c<dimensions_of_parkhouse[2];c++){
//p2parkboxes[f][r][c] is the instance of the class Pakbox
if(p2parkboxes[f][r][c]==EMPTY)
{
next_free_parking_position[0]=p;
next_free_parking_position[1]=r;
next_free_parking_position[2]=c;
}
}
}
}
}
어떻게 어느 시점에서 "p2parkboxes[f][r][c]==EMPTY
"그것은 나에게 오류를 제공하는 "더 연산자 없다" == "이 피연산자와 일치합니다",. 그렇다면 클래스 인스턴스를 EMPTY 같은 다른 변수와 직접 비교하려면 어떻게해야합니까?
나는 당신이 분명할지 모르겠다. 하지만이 문제를 해결하지 못하면 코드 작성을 계속할 수 없기 때문에 도와주세요.
'p2parkboxes [f] [r] [c]'유형의 정의를 게시 할 수 있습니까? – hmjd
예 다음과 같이 선언합니다. class ParkingGarage { Parkbox *** p2parkboxes; 그리고 나는 CTOR와 객체를 생성했다 : ParkingGarage :: ParkingGarage (const int rw, const int clm, const int plns) { \t p2parkboxes = new Parkbox ** [plns]; // 바닥을 가리키고 (평면 p = 0; p + p ++) { \t \t p2parkboxes [p] = 새로운 Parkbox * [plns]; // 각 평면에 대해 포인터의 배열을 만듭니다. 즉, 행과 동일 NUM 위한 \t \t (INT에서 R = 0, R
mrmrk
그리고 'Parkbox'? – hmjd