참조로 추상 클래스의 객체를 전달하려고 시도했지만이 객체를 동일한 데이터 유형의 포인터 배열에 저장하려고하면 분명히 오류가 발생합니다. 아무도 내가 뭘 잘못 설명 할 수 있을까요? 은 다음과 같은 기능에있어 : 배열에 추상 객체를 저장하는 C++
void enterItem(DessertItem& item)
{
if (top != (maxSize-1))
{
arr[top] = &item;
top++;
}
}
dessertItem 클래스는 실제로는 추상 클래스이며, 그것을 참조로 전달되는 때마다 새로운 개체에 대한 참조를 제공 할 수 있도록 "편곡"dessertItem의 포인터 배열입니다. 나는 그것을 어떻게 해야하는지 알 수 없다.
class Checkout
{
////Maintains a list of DessertItem references.
protected:
int maxSize;
int top;
DessertItem **arr;
public:
Checkout()
{
///Creates a Checkout instance with an empty list of DessertItem's
this->maxSize=5;
this->top=0;
this->arr = new DessertItem*[maxSize];
for(int i=0; i<maxSize; i++)
{
arr[i]=NULL;
}
}
////Clears the Checkout to begin checking out a new set of items
void clear()
{
for(int i=0; i<maxSize; i++)
{
arr[i]=NULL;
}
}
//A DessertItem is added to the end of the list of items
void enterItem(DessertItem &item)
{
if(top!=(maxSize-1))
{
arr[top]=&item;
top++;
}
}
//Returns the number of DessertItem's in the list
int numberOfItems()
{
return this->top;
}
};
이 우리에게 당신이 표시되는 오류 메시지를 보여주십시오. – jweyrich
예상되는 타입 지정자입니다. 실제로 그게 무슨 뜻 이죠? –
여기서는 arr이고 상단은 정의 되었습니까? –