1

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?

Ashok
  • 1,079
  • 3
  • 10
  • 17
  • 2
    Looking at the documentation, just plain `int val = p["some_value"];` should work. – Igor Tandetnik Jul 16 '13 at 00:38
  • Thank you! My type was uint32_t instead of native type int, and hence there was no matching overloaded function. But I changed it to int and now it works. – Ashok Jul 16 '13 at 00:48

2 Answers2

1

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

Iwan Aucamp
  • 1,469
  • 20
  • 21
  • Thanks for the explanation. My type was uint32_t instead of native type int, and hence there was no matching overloaded function and hence the errors. But I changed it to int and now it works. – Ashok Jul 16 '13 at 00:50
1
if(p.getType() ==  TypeInt)
    int val = p;

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

aamir
  • 151
  • 6