将数组分配给自定义结构

问题描述 投票:0回答:0

我有这段代码,它将 8 个元素的数组分配给一个指向自定义结构 (Input_Leo) 的实例 j 的指针:

在CFNN.cpp中:

 {
     double tx_tech_variable_vec[8] = { 0 }; //I need this re-initialization // code testing:   variable rates on the initial premium payment of FIB/Invest Products with a time-variable garantueed interest rate */*/
     tx_tech_variable_vec[0] = 3.0; // it does not help to declare it in CFNN.H, as part of the InputLeo structure, you have to do it here before also
     tx_tech_variable_vec[1] = 1.5;
     DATE tx_tech_variable_dates_vec[8] = { 0, 0 }; // initialization
     tx_tech_variable_dates_vec[0] = { 2026, 07 };
     tx_tech_variable_dates_vec[1] = { 2032, 07 }; // assignment
     
     j->tx_tech_variable_vec = tx_tech_variable_vec; // overwrites everything (so for each contract (subcontract?), a new vector is written to j)
     j->tx_tech_variable_dates_vec = tx_tech_variable_dates_vec; // overwrites everything (so for each contract (subcontract?), a new vector is written to j)
 }

在 CFNN.H 中:

struct Input_Leo /* input for Leo  */
{
    DATE calculation_date = { 2000, 0 };                    // Calculation date (used for RADP as date of the payment of unexpected premium)
    DATE   cohortmonthly = { 2000, 0 };                 //date payement prime conclusion (used in total business mode for the month of payment of yearly premiums, to know if we reached 12 months of historic of unex premiums)
    int lnumcon = 0;                            // Contract number
    int cregfsc = 0;                            

and so on...

  double* tx_tech = nullptr;                // pointer on Tx_res_LEO to allow for dynamic memory allocation, depending on the number of subcontracts
  double tx_tech_variable_vec[8] = {0};
DATE tx_tech_variable_dates_vec[8] = {0, 0}; /* code testing not sure I need to add it here */
    
};

我收到此错误:

线路严重性代码描述项目文件抑制状态 4681 错误 C3863 数组类型 'double [8]' 不可分配 CF_2012_V7 C:\Users\U03630\Source\Repo

c++ arrays pointers structure variable-assignment
© www.soinside.com 2019 - 2024. All rights reserved.