当前位置: 代码迷 >> Ruby/Rails >> error C2227: left of '>first' must point to class/struct/union
  详细解决方案

error C2227: left of '>first' must point to class/struct/union

热度:311   发布时间:2016-04-29 02:13:58.0
error C2227: left of '->first' must point to class/struct/union

今天调试程序时,遇到这么一个错误:

error C2227: left of '->first' must point to class/struct/union

#include<iostream>using namespace std;#define ElemType intstruct node{	struct node *first;	struct node *last;	int size;};typedef struct node Node;typedef struct node *PNode;typedef PNode List;void Initlist(List *list){	*list->first = *list->last = (node *)malloc(sizeof(node));	*list->size = 0;}int main(){	List mylist;	Initlist(&mylist);	return 0;}


错误如下:


到底哪出错了呢?????

原来:->优先级(高于)*

*list->last ===>>>>>*(list->last),*list是指向结构体的指针,而list不是,,现在知道错误的原因所在了吧!!!注意哦!!

将*list->last -------改为-------->>>(*list)->last,问题就解决了

  相关解决方案