我有這個類和結構,並且數組上的每個結構連接到另一個結構(每個數組元素上的鏈表結構).. btw這只是我的一個樣本代碼中,假定沒有其他錯誤..結構數組似乎不想工作
class DATA;
class myclass
{
public:
myclass();
mystruct* addDATA(DATA *d);
private:
mystruct* array;
};
struct mystruct
{
DATA * data;
mystruct * next ;
};
在構造函數中我想這
mystruct::mystruct()
{
mystruct* array = new mystruct[10];
for(int i = 0; i < 10; i++)
array[i] = NULL;
}
這給出了一個出乎意料的(至少對我來說)的錯誤,這不是錯誤位可笑的是,我正在指出指向NULL。
no match for ‘operator=’ in ‘*(array + ((unsigned int)(((unsigned int)i) * 8u))) = 0’
而且當我嘗試;
while(this->array[i] != NULL){
// do some arrangements on the array..
}
這也給出了同樣的錯誤。爲什麼會匹配指針爲NULL給這個錯誤,或者檢查是否從今天早上起的NULL或not..Struggling,找不到* *荷蘭國際集團解決方案:/ 數組的類型是「mystruct」,但沒有別的,這是一個問題嗎?或者數組[i]不是一個指針或什麼?
你有一個值的數組,並試圖將這些值視爲指針,爲什麼你會期望這個值工作?你的目標是什麼? – ildjarn
我該如何解決這個問題,我的意思是我必須使用這個結構類型和類,如何檢查它是否爲NULL – Karavana
只有指針可以爲null,將mystruct'與null進行比較意味着什麼? – ildjarn