繁体   English   中英

c ++ map stl错误:数组'apn2policy'的大小具有非整数类型'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 list,但是当更改为map时,出现此错误。

谢谢,PDK

APN2PolicyRules apn2policy["Apn_Internet"]=ipAddrPolicyRules;

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

您最有可能要做的是:

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

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

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

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

如您所见, Foo[Bar]语法在不同的上下文中表示不同的内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM