c++ - 从标头生成 gSOAP 文件时定义无法识别
问题描述
我正在尝试从头文件生成 gsoap 类
soapcpp2.exe test.h
在哪里 test.h
// test.h
#define MY_STRUCT_NAME_LEN 50
typedef struct MY_STRUCT_TYPE
{
char name[MY_STRUCT_NAME_LEN];
}MY_STRUCT;
int op1(MY_STRUCT* a, int b, int * r );
我的问题是#define MY_STRUCT_NAME_LEN 50
al line:3 未被识别。
test.h(7): *WARNING*: undefined identifier 'MY_STRUCT_NAME_LEN'
test.h(7): *WARNING*: char[30681240620171331] will be serialized as an array of 30681240620171331 bytes: use soapcpp2 option -b to enable char[] string serialization or use char* for strings
test.h(7): **ERROR**: undetermined array size
Saving soapStub.h annotated copy of the source interface header file
Saving soapH.h serialization functions to #include in projects
test.h(12): *WARNING*: serializable typedef 'MY_STRUCT' is not namespace qualified: schema definition for 'MY_STRUCT' in WSDL file output may be invalid
Saving soap.nsmap namespace mapping table
Saving soapClient.cpp client call stub functions
Saving soapClientLib.cpp client stubs with serializers (use only for libs)
Saving soapServer.cpp server request dispatcher
Saving soapServerLib.cpp server request dispatcher with serializers (use only for libs)
Saving soapC.cpp serialization functions
There were errors:
1 semantic error
3 warnings
如果我将 line:7 更改为
char name[50];
它会正常工作。
我真的更喜欢使用宏来确定字符串的大小(实际情况更复杂)。有人可以帮忙吗?
解决方案
由于这个问题被标记为 C++ 并且您使用的是 soap cpp 2:您可能不应该使用定义typedef struct ...
和字符串的字符数组。这就是说,如果没有特别的理由限制字符串长度,请将您的代码重写为:
class test {
public:
std::string name;
};
int op1(test* a, int b, int * r );
结果编译成功,没有任何警告。
推荐阅读
- javascript - CSS禁用部分图标的缩放动画
- r - 如何将具有逗号分隔值的因子转换为 R 中的数字向量?
- python - python中&和和的区别
- browser - Gecko WebBrowser 在重新启动机器后第一次无法打开特定链接
- django - Django REST框架嵌套序列化程序中的“此字段是必需的”
- .net - 如何解决从前端向另一个使用另一个 .NET Core 应用程序作为身份服务器的 MVC 应用程序发出请求的应用程序中的 CORS 问题
- postgresql - 检查一组列是否具有科学价值
- flutter - flutter_launcher_icons --- 在 pubspec.yaml 中检测到错误:
- mysql - MySql,在 ON DUPLICATE KEY 内的子查询中使用值
- excel - Laravel excel:在使用集合时读取特定行