I am new to C++ and converting my code that I have written in C into C++.
here is the struct code.
typedef struct {
uint16_t index; /**< PDO entry index. */
uint8_t subindex; /**< PDO entry subindex. */
uint8_t bit_length; /**< Size of the PDO entry in bit. */
} ec_pdo_entry_info_t;
and here is the declaration of struct in C-lang.
ec_pdo_entry_info_t slave_0_pdo_entries[] =
{
{ 0x6040, 0x00, 16 }, // 0
{ 0x607a, 0x00, 32 }, // 2
{ 0x60b0, 0x00, 32 }, // 6
{ 0x60b1, 0x00, 32 }, // 10
{ 0x60b2, 0x00, 16 }, // 14
{ 0x6060, 0x00, 8 }, // 16
{ 0x2078, 0x01, 16 }, // 17
{ 0x60b8, 0x00, 16 }, // 19
{ 0x6041, 0x00, 16 }, // 21
{ 0x6064, 0x00, 32 }, // 23
{ 0x606c, 0x00, 32 }, // 27
{ 0x6077, 0x00, 16 },
{ 0x6061, 0x00, 8 },
{ 0x2071, 0x01, 16 },
{ 0x60b9, 0x00, 16 },
{ 0x60ba, 0x00, 32 },
{ 0x60bb, 0x00, 32 },
};
I have made a class in which I have declared a variable like below,
ec_pdo_entry_info_t slave_0_pdo_entries[];
Now in a constructor I want to declare slave_0_pdo_entries[] variable as I have done in c-lang. Could you please help guide me how can I do this?
Etherlabinterface::Etherlabinterface()
{
master=NULL;
domain0=NULL;
sc_epos3=NULL;
domain0_output=NULL;
slave_0_pdo_entries[]=
{
{ 0x6040, 0x00, 16 }, // 0
{ 0x607a, 0x00, 32 }, // 2
{ 0x60b0, 0x00, 32 }, // 6
{ 0x60b1, 0x00, 32 }, // 10
{ 0x60b2, 0x00, 16 }, // 14
{ 0x6060, 0x00, 8 }, // 16
{ 0x2078, 0x01, 16 }, // 17
{ 0x60b8, 0x00, 16 }, // 19
{ 0x6041, 0x00, 16 }, // 21
{ 0x6064, 0x00, 32 }, // 23
{ 0x606c, 0x00, 32 }, // 27
{ 0x6077, 0x00, 16 },
{ 0x6061, 0x00, 8 },
{ 0x2071, 0x01, 16 },
{ 0x60b9, 0x00, 16 },
{ 0x60ba, 0x00, 32 },
{ 0x60bb, 0x00, 32 }
};
constructor to initialize struct. Answer I have accepted is working but I am facing new problem, this array will be used by another array but when I but this thing in that it is giving me different error.
after initializing array as accepted answer, I neeed to initialize another array, see below,
ec_pdo_info_t slave_0_pdos[] = {
{0x1605, 7, slave_0_pdo_entries + 0},
{0x1a02, 5, slave_0_pdo_entries + 7},
}
In above array it is giving error + operator is not valid..
after above array I need to initialize another array like below,
ec_sync_info_t slave_0_syncs[] = {
{0, EC_DIR_OUTPUT, 0, NULL, EC_WD_DISABLE},
{1, EC_DIR_INPUT, 0, NULL, EC_WD_DISABLE},
{2, EC_DIR_OUTPUT, 1, slave_0_pdos + 0, EC_WD_ENABLE}};
It is showing me same error..kindly guide me.. Thank you.