2014-01-07 46 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 
} 
相關問題