错误将结构复制到同一类型的另一种

Error copying the structure to another of same type

本文关键字:类型 另一种 结构 复制 错误      更新时间:2023-10-16

以下是C 片段,

struct node {
    struct shm_ipc_msg_s msg;
    struct node *next;
};
enqueue_shm_events(Queue *q, shm_ipc_msg *msg)
{
    struct node *temp = new node;
    temp->msg = msg;      // error here!!!!
    if (q->front == NULL)
       q->front = temp;
    else
       q->rear->next = temp;
}

错误:

error: no match for 'operator=' in 'temp->node::msg = msg'

任何人都可以帮助我纠正此错误

预先感谢

您有两个问题:

  1. 您的类型名称是不同的
  2. 您将指针分配给非分数

修复1:各种修复程序。一种可能性是typedef struct shm_ipc_msg_s shm_ipc_msg

修复2:将失败线更改为temp->msg = *msg;以将指针放置,以便您可以复制实际的结构内容

相关文章: