2014-01-07 38 views

回答

1

而不是使用getElementAsInt32使用getValueAs的错误:

Element field; 
int err=msg.asElement().getElement(&field, BID_SIZE); 
if (!err) 
{ 
    int valerr=field.getValueAs(&bid_sz); // will call getValueAs for the type of bid 
} 

这将避免在消息中寻找BID_SIZE两次,而不会抛出w ^没有找到母鸡场。

另外,您可以通过各个领域的循环,并检查它是哪场:

Element asElem=msg.asElement(); 
size_t num=asElem.numElements(); 
for (size_t i=0; i < num; ++i) 
{ 
    Element field=asElem.getElement(i); 
    Name field_name=field.name(); 
    if (field_name == BID_SIZE) 
    { 
     bid_sz=field.getValueAsInt32(); 
    } 
    // check other fields 
    // put more likely fields at the top 
} 
相关问题