2012-02-29 81 views
1

我使用gSoap在头文件中创建一个Web服务我有几个方法定义,它们的返回类型是枚举值。 当我执行soapcpp2.exe刀具和头文件我得到这个错误传递:枚举类型作为soapCpp2中的返回值

sample.h(20): syntax error 
sample.h(21): Syntax error: input before ; skipped 

另外,如果我有一个以上的方法,用枚举作为返回值I” m如果这样的警告:

**WARNING**: Duplicate declaration of 'sample_status_____' (already declared at li ne 31), changing conflicting identifier name to new name sample_status______'. Note: this problem may be caused by importing invalid XML schemas (detected at line 38 in sample.h)

我的头文件看起来像这样:

// enum definition 
enum status {ok, error}; 

// method definition 
status ns_calc(int a, int b); 

是它soapcpp.exe的限制?

回答

3

你正在写的头文件必须遵循一些gSoap约定。因此函数的输出必须是最后一个参数。从documentation

By convention, all parameters are input parameters except the last. The last parameter is always the output parameter. A struct or class is used to wrap multiple output parameters, see also Section 7.1.9. This last parameter must be a pointer or reference. By contrast, the input parameters support pass by value or by pointer, but not pass by C++ reference.

在头文件中的相关部分看起来像:

enum ns__status { ok, error }; 
int ns__calc(xsd__int a, xsd__int b, enum ns__status& out); 

注意这个例子明确使用XML的架构(xsd__)类型,this practice is advised to improve interoperability。 cpp文件中的相关部分如下所示:

int ns__calc(struct soap* soap, xsd__int a, xsd__int b, enum ns__status& out) 
{ 
    // do something with 'a' and 'b' and set 'out' 
    out = ... 
    return SOAP_OK; 
}