在项目调试过程中,碰到 一个这样的问题,c++结构体赋值问题。在c语言中,一个结构体变量是可以赋值给另外一个结构体变量的。在c++情况有所变化,仅此记录一下. 此为一个概率事件。
//定义接收数据数据,对内发布的消息节点.
typedef struct msg_node{
int id; //消息id
enum MSG_TYPE msgType; //消息类型.
string msgName; //填充消息名称.
string strLoad; //处理后的消息负载.
uint8_t state;//未执行,正在执行, 执行成功,执行失败
int priority; //消息优先级
void msg_node_copy(const struct msg_node & node)
{
id = node.id;
msgType = node.msgType;
msgName = node.msgName;
strLoad = node.strLoad;
state = node.state;
priority = node.priority;
}
}msg_node_t;
当结构体成员中,有string类型数据,并且每次都是一个 可变长的数据的时候,如果采用结构体直接赋值,可能有问题,
请使用方法赋值,特此记录一下。