错误将结构复制到同一类型的另一种
Error copying the structure to another of same type
以下是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:各种修复程序。一种可能性是typedef struct shm_ipc_msg_s shm_ipc_msg
修复2:将失败线更改为temp->msg = *msg;
以将指针放置,以便您可以复制实际的结构内容
相关文章:
- 文本冒险游戏 - 如何区分一种项目类型与另一种项目类型以及如何构建项目类/子类
- 当 c++ 需要一种数据类型并获取另一种数据类型时会发生什么?
- 另一种类型的智能ptr,比如具有弱refs的unique_ptr
- void* 数组将元素转换为另一种类型
- 在 c++ 中将一种结构类型分配给另一种类型
- 将空基类优化对象强制转换为另一种类型是否会破坏严格的别名?
- 如何测试指针类型是否可以安全地转换为另一种指针类型?
- 将 32 位浮点数和不强制转换的 32 位整数与双精度进行比较,当其中一个值可能太大而无法完全适合另一种类型时
- 错误将结构复制到同一类型的另一种
- 何时与另一种类型兼容
- 将指向结构的指针转换为具有较少字段数的另一种结构类型
- 是否可以将一种函数类型转换为另一种采用相同参数但返回类型不同的函数类型
- 自动将一种 c++ 类型转换为另一种
- C 模板可以匹配(仅)一种类型的列表或另一种类型的列表
- 是否可以将一种类型的数组转换为大小不同的另一种类型的数组?
- 在比较中使用已强制转换为另一种类型的函数指针是否定义良好?
- 多态变体,并将一种类型的引用绑定到另一种类型的引用
- 如何使用模板元编程在 C++17 中将一种类型转换为另一种类型
- 将字符阵列施放到另一种类型中是否违反了严格的确定规则
- 创建一个从一种类型到另一种类型的别名