I have a XmlRpcValue object and want to get the values from this object. The Class offers some interfaces to get the values. But I'm not sure how to use them. The interface is defined in this minimal documentation (http://xmlrpcpp.sourceforge.net/doc/classXmlRpc_1_1XmlRpcValue.html#_details). I tried calling the overloaded function () but I'm not sure of the correct syntax of calling this function.

Simplified code is as follows:

XmlRpc::XmlRpcValue p;
cout<<p["some_value"]<<endl;
int val = p["some_value"]();

The compilation error arises in line 3 above. The cout statement prints the proper value. I have tried several permutations of the overloaded operator (), but everything only causes a different compilation error. How should I get the value from this object?

有帮助吗?

解决方案

You are confusing R T::operator ()(S a1, U a2, ...); with T::operator R(); - the latter is conversion operator - the former is function call operator. In this case XmlRpcValue has conversion operators specified - these are called implicitly in cases like int val = p["some_value"]; as suggested by Igor

其他提示

if(p.getType() ==  TypeInt)
    int val = p;

This should work as there is conversion operator defined for XmlRpcValue operator int&();

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top