函数返回指向另一种函数的指针 - C ++

时间:2015-07-11 10:12:12

标签: c++ pointers

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ser="http://tempuri.org/RATEINQ/Service1"> 
    <soapenv:Header/> 
    <soapenv:Body> 
      <ser:RateInq> 
        <ser:LoginName>'.MODULE_SHIPPING_LOOMISEXPRESS_USERNAME.'</ser:LoginName> 
        <ser:Password>'.MODULE_SHIPPING_LOOMISEXPRESS_PASSWORD.'</ser:Password> 
        <ser:ShipperAccountNumber>'.MODULE_SHIPPING_LOOMISEXPRESS_ACCUNTNUMBER.'</ser:ShipperAccountNumber> 
        <ser:FromPostalCode>'.MODULE_SHIPPING_LOOMISEXPRESS_FROM_POSTAL_CODE.'</ser:FromPostalCode>
        <ser:ToPostalCode>'.$to_postal.'</ser:ToPostalCode> 
        <ser:ToCity>'.$add_city.'</ser:ToCity> 
        <ser:ToProvinceCode>'.$add_state.'</ser:ToProvinceCode> 
        <ser:ToCountryCode>'.$country_id.'</ser:ToCountryCode> 
        <ser:ServiceType>ALL</ser:ServiceType> 
        <ser:PickupDate>'.date('Y-m-d', strtotime($currdate . ' + 1 day')).'</ser:PickupDate> 
        <ser:UOM>I</ser:UOM> 
        <ser:Pieces>'; 
        for($i=0; $i<$ttl; $i++)
        {
            for($j=0; $j<$products[$i]['quantity']; $j++)
            {
     $xml .= '<ser:Piece> 
               <ser:Weight>'.$products[$i]["weight"].'</ser:Weight> 
               <ser:Length>0</ser:Length> 
               <ser:Width>0</ser:Width> 
               <ser:Height>0</ser:Height> 
         </ser:Piece>';
            } 
         }
       $xml .= '</ser:Pieces> 
         <ser:ValuationAmount>'.MODULE_SHIPPING_LOOMISEXPRESS_VALUATION_AMOUNT.'</ser:ValuationAmount> 
         <ser:IsNonPack>'.MODULE_SHIPPING_LOOMISEXPRESS_ISNONEPACK.'</ser:IsNonPack> 
         <ser:IsDangerousGood>'.MODULE_SHIPPING_LOOMISEXPRESS_ISDANGEROUSGOOD.'</ser:IsDangerousGood> 
         <ser:IsSaturdayDelivery>'.MODULE_SHIPPING_LOOMISEXPRESS_ISSATURDAYDELIVERY.'</ser:IsSaturdayDelivery> 
         <ser:IsFragile>'.MODULE_SHIPPING_LOOMISEXPRESS_FRAGILE.'</ser:IsFragile> 
         <ser:IsResidential>'.MODULE_SHIPPING_LOOMISEXPRESS_RESIDENTIAL.'</ser:IsResidential> 
         <ser:IsDutiable>'.MODULE_SHIPPING_LOOMISEXPRESS_CHAINOFSIGNATURE.'</ser:IsDutiable> 
         <ser:IsDTP>'.MODULE_SHIPPING_LOOMISEXPRESS_DTP.'</ser:IsDTP> 
         <ser:Language>'.MODULE_SHIPPING_LOOMISEXPRESS_LANGUAGE.'</ser:Language> 
      </ser:RateInq> 
    </soapenv:Body> 
    </soapenv:Envelope> 

我有错误:错误返回值类型与函数类型不匹配。

有什么问题?

1 个答案:

答案 0 :(得分:2)

这会有所帮助:

bool (__fastcall fun)(float par1, float par2)
{
    return (par1 == par2) ? true : false;
}

bool (__fastcall *newFun(std::string str))(float par1, float par2)
{
    //...
    return fun;
}

int main()
{
    auto p = newFun("someString");
    cout << p(1.0, 1.0) << endl;
    cout << p(1.0, 1.1) << endl;
    return 0;

}

也许您想阅读How do function pointers in C work?

我认为这是对函数指针的一个很好的讨论。