struct Apartment {
    int floor;      // aparment's floor
};

void main() {
    Apartment apartments[10];// array containing all the apartments

    create_apartments(apartments);
};

void create_apartments(struct Apartment *apartments) {
   int i,pos;

   pos=0;
   for(i=0;i<10;i++){
       *(apartments+pos)->floor = i;  //error apears here!
        pos++;
    }
}


一元“ *”(具有“ int”)的无效类型参数出现在注释行。有人可以告诉我怎么了吗?谢谢 :)

最佳答案

->运算符已取消引用指针。再次应用*尝试取消引用(apartments+pos)->floor类型的int。删除*

编辑:甚至更普遍地写这个:

    apartments[pos].floor = i;

关于c++ - 一元“*”的无效类型参数(具有“int”),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21760906/

10-11 17:08