Code ForLife Code ForLife - 18 days ago 5
C Question

error: request for member ‘prev_’ in something not a structure or union

I did a search for this error:


error: request for member ‘prev_’ in something not a structure or union


And every suggestions were to use
->
but in my case I'm using
->
already.

Here is my code:

struct student_record_node
{

struct student_record* record_;
struct student_record_node* next_;
struct student_record_node* prev_;
};

void swap(struct student_record_node** node1, struct student_record_node** node2)

{

struct student_recod_node* prev_;
struct student_recod_node* next_;

if(*node1->prev_)
{
node1->prev_->next_ = node2;
}

if(*node2->prev_)
{
node2->prev_->next_ = node1;
}
}

Answer
if(*node1->prev_)

-> has higher operator precedence than *. The above statement is equivalent to:

if (*(node1->prev_))

Since node1 does not point to a structure with such a class member, that's the reason you're getting this compilation error. This should be changed to:

if((*node1)->prev_)

The same fix is needed in the rest of the shown code. For example:

node1->prev_->next_ = node2;

This probably should be:

(*node1)->prev_->next_ = *node2;