有时候,当进行通信架构迁移时,会遇到消息格式不一致的兼容性问题,可采用定义内嵌引用的方式来解决,如下示例:
1 #include <iostream> 2 3 class A { 4 5 int a = 1; 6 int& b; 7 8 struct Request { 9 int c; 10 } request; 11 12 public: 13 A() : b(request.c) {} 14 15 void output() { 16 request.c = 1; 17 std::cout << "c:" << request.c << std::endl; 18 std::cout << "b:" << b << std::endl; 19 b = 4; 20 std::cout << "c:" << request.c << std::endl; 21 std::cout << "b:" << b << std::endl; 22 } 23 24 }; 25 26 int main() 27 { 28 A a; 29 a.output(); 30 return 0; 31 }
按上述方法,即可使原数据类型 "b"和新增的Request类型中的"c"是同一个数据,实现兼容。
标签:架构,int,request,Request,格式,迁移 From: https://www.cnblogs.com/qyit/p/17355092.html