0

有什么方法可以获取我的 boost::any 对象的类型值以将其用于 any_cast?

    POSITION dictPos = CurrentSubMap->GetStartPosition();
    while(dictPos)
    {

        boost::any a = CurrentSubMap->GetValueAt(dictPos);
        if(a.type() == typeid(long))
            dictToAppend[CurrentSubMap->GetNextKey(dictPos)] = boost::any_cast<long>(a); 
        else
            dictToAppend[CurrentSubMap->GetNextKey(dictPos)] = boost::any_cast<CAtlString>(a);


    }

它有效,但我需要一个动态解决方案,例如:

dictToAppend[CurrentSubMap->GetNextKey(dictPos)] = boost::any_cast<HERE_THE_TYPE_OF_a>(a);

我用“a.type()”试过了,但它不起作用。

“'ValueType' 的模板参数无效,预期类型”

4

0 回答 0