首页 > 解决方案 > Identical objects but different types

问题描述

I use a C++ app to synchronyze data between two PHP servers.

My first server is local, my C++ app call a webservice on that server to get an object to synchronyze. Then, my C++ app use another webservice to send it on my Cloud PHP server.

So my Object is a soap object defined strictly identically on my two php server.

However, for my C++ apps, these two object are not the same (or at least with a different namespace), so Y can't compile the following line:

soapErrorCode = cloudWebService.action(myLocalObject);
//C++ is waiting for an object of type myCloudObject, even if these two object have the same attributes

My soap objects and Webservice definition are defined in my C++ with help of gSoap.

I see different solution, but not sure which is the best:

  1. Is there a way to tell to C++ that myLocalObject and myCloudObject are the same? Note: I don't want manually modify the code generated by gsoap (too much work!).
  2. Is there a way to tell to gsoap that myLocalObject and myCloudObject are the same?
  3. Am I obliged to create fonction to convert myLocalObject to myCloudObject?

Thanks!

标签: c++web-servicesgsoap

解决方案


In my opinion two possible variants are:

  1. Write converter function from myLocalObject to myCloudObject and from from myCloudObject to myLocalObject
  2. You can make a base class for myLocalObject and myCloudObject and work through its pointer.

推荐阅读