미치겠군요....
EAccess Violation 에러가 계속 뜹니다...
이거 어떻게 잡을수 없을까요?
PLANE _fastcall QUEUE::Delete()
{
LinkQueue* temp;
// Because the first node is head node, do like below.
temp=front->link;
if(GetSize()>1) front->link=temp->link; // Because of EAccess Violation.
else front->link=NULL;
return temp->plane;//TempPlane;
}
젤 아랬부분인데.....
struct LinkQueue {
PLANE plane;
LinkQueue* link;
};
보시다시피 LinkQueue구조체는 위와같이 선언되었습니다...
왜 이런상황에서......temp->plane;부분이 Access Violation 이라는 건지...
이해가 돼질 않습니다...
시간이 없습니다...
가능한 빨리 답변해 주시기 바랍니다...
무엇이 문제입니까~~~~~~~~~~~~~~~
front->link=temp->link;도 Access Violation 에러가 났는데...
약간 고쳐서 수정했습니다.....
참고로 모든 코드를 올립니다.
이부분이 클래수 부분입니다.
링크드리스트로된 큐를 짜기위해서 QUEUE클래스에 속하는 구조체인 LinkQueue
를 선언해놨습니다.
class PLANE {
public:
_fastcall PLANE();
void _fastcall SetReady(bool temp) { ready=temp; }
bool _fastcall GetReady() { return ready; }
void _fastcall SetFuel(int n) {
if(n>30) fuel=30;
else if(n<0) fuel=0;
else fuel=n;
}
int _fastcall GetFuel() { return fuel; }
void _fastcall DownFuel() { if(fuel>0) fuel--; }
void _fastcall SetWaitingTime(int temp);
int _fastcall GetWaitingTime() { return waiting_time; }
private:
int ID;
int fuel;
bool ready;
int waiting_time;
};
struct LinkQueue {
PLANE plane;
LinkQueue* link;
};
class QUEUE {
public:
_fastcall QUEUE();
//~QUEUE();
void _fastcall Add(PLANE item);
PLANE _fastcall Delete();
int _fastcall GetSize();
bool _fastcall IsEmpty() {
if(front==rear) return true;
else return false;
}
void _fastcall DownFuel();
//void SetWaitingTime(int n);
//int GetWaitingTime();
private:
LinkQueue *front,*rear;
};
그리고 아랜 멤버 함수들입니다...
급하게 짠거라 코드들이 좀 지저분합니다...
_fastcall PLANE::PLANE()
{
ID=NumberOfPlanes++;
randomize();
fuel=random(30)+1;
ready=false;
waiting_time=NULL;
}
void _fastcall PLANE::SetWaitingTime(int temp)
{
if(temp<0) temp=-temp;
waiting_time=temp;
}
//---------------------------------------------------------------------------
// Member functions of the Queue class.
_fastcall QUEUE::QUEUE()
{
LinkQueue* temp=new LinkQueue;
temp->link=NULL;
front=temp;
rear=temp;
}
/*
QUEUE::~QUEUE()
{
LinkQueue* temp;
do {
temp=front;
front=front->link;
delete temp;
}while(front!=NULL);
}
*/
void _fastcall QUEUE::Add(PLANE item)
{
// Special code. Though, this code must be erased.
// But for easy to coding, this code is allocated here.
// Waiting time is equal to size of the queue.
item.SetWaitingTime(GetSize());
LinkQueue* temp=new LinkQueue;
temp->link=NULL;
temp->plane=item;
rear->link=temp;
rear=temp;
}
PLANE _fastcall QUEUE::Delete()
{
LinkQueue* temp;
// Because the first node is head node, do like below.
temp=front->link;
if(GetSize()>1) front->link=temp->link; // Because of EAccess Violation.
else front->link=NULL;
return temp->plane;//TempPlane;
}
이상입니다...
제발!~~수고좀 해주시기 바랍니다..
|