c++ map stl error : size of array 'apn2policy' has non-integral type 'const char [13]'

c++ map stl error : size of array 'apn2policy' has non-integral type 'const char [13]'

我有以下 typedef

struct PolicyRuleInfo{
    BearerQoSInfo stBearerQoS;
    TFTInfo stTFTInfo;

    PolicyRuleInfo(){};
    PolicyRuleInfo( BearerQoSInfo const& qos, TFTInfo const& tft)
       : stBearerQoS(qos), stTFTInfo(tft)
    { }
};

typedef map<string, PolicyRuleInfo> listOfPolicyRuleInfo;

struct IPAddressPolicyRulesInfo{
    CIPAddress ipAddress;
    listOfPolicyRuleInfo policyRules;
    IPAddressPolicyRulesInfo(){};
    IPAddressPolicyRulesInfo(CIPAddress ipaddr, string policyRuleName, PolicyRuleInfo policyRule): ipAddress(ipaddr){policyRules[policyRuleName]=policyRule;};

    void addPolicycyRule(string policyRuleName, PolicyRuleInfo policyRule) { policyRules[policyRuleName]=policyRule; }
};

typedef map<string, IPAddressPolicyRulesInfo> APN2PolicyRules;

typedef map<string, APN2PolicyRules>     IMSI2APNPolicyRules;

稍后在 cpp 中:

u32 CPCRF::m_pNumPCCRulesViaCLI = 0;

listOfPolicyRuleInfo CPCRF::m_mlistOfCliConfiguredPolicyRules;

// map IMSI to PolicyRules
IMSI2APNPolicyRules         CPCRF::m_mIMSI2PCRFInfo;

// Assign some default Policies (Applicable to all subscribers) , can be changed via CLI
listOfPolicyRuleInfo m_mlistOfCliConfiguredPolicyRules = boost::assign::map_list_of("PolicyRule_Internet", PolicyRuleInfo( BearerQoSInfo(9), TFTInfo()))
                                                                                                                                         ("PolicyRule_Voice_C", PolicyRuleInfo( BearerQoSInfo(5), TFTInfo()))
                                                                                                                                         ("PolicyRule_Voice_U", PolicyRuleInfo( BearerQoSInfo(1), TFTInfo()));

    listOfPolicyRuleInfo::iterator it = m_mlistOfCliConfiguredPolicyRules.find("PolicyRule_Internet");

    if (it != m_mlistOfCliConfiguredPolicyRules.end() )
    {
        IMSI2APNPolicyRules::iterator itr= m_mIMSI2PCRFInfo.find(imsi);

        if (itr == m_mIMSI2PCRFInfo.end() )
        {
            IPAddressPolicyRulesInfo ipAddrPolicyRules(ueIPAddress, "PolicyRule_Internet", it->second);

            APN2PolicyRules apn2policy["Apn_Internet"]=ipAddrPolicyRules;

            m_mIMSI2PCRFInfo[imsi] = apn2policy;

我收到错误消息说数组 'apn2policy' 的大小具有非整数类型 'const char [13]'

早些时候我将 listOfPolicyRuleInfo 声明为 typedef 列表,但是当更改为映射时,出现此错误。

谢谢, PDK

APN2PolicyRules apn2policy["Apn_Internet"]=ipAddrPolicyRules;

这是错误的;你正在声明一个 "Apn_Internet" × APN2PolicyRules 对象的数组,这显然是胡说八道!

您必须先创建地图然后使用它:

APN2PolicyRules apn2policy; // (if it doesn't already exist)
apn2policy["Apn_Internet"] = ipAddrPolicyRules;

如您所见,Foo[Bar] 语法在不同的上下文中有不同的含义。

APN2PolicyRules apn2policy["Apn_Internet"]=ipAddrPolicyRules;

这一行试图声明一个 APN2PolicyRules 的数组,但大小参数是一个没有任何意义的字符串文字。

您最有可能想做的是:

APN2PolicyRules apn2policy; // create map
apn2policy["Apn_Internet"]=ipAddrPolicyRules; // set rule