A
A
Aleksandr Sechko2020-06-22 14:15:18
C++ / C#
Aleksandr Sechko, 2020-06-22 14:15:18

What is happening in these lines of code?

ceh *p;
p = new ceh[2];
p->set("Ivan", "moroz", 12);
void (ceh::*pf)();
pf = &ceh::show;
(p[0].*pf)();


Please explain how to initialize the rest of the array elements.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Victor Bomberow, 2020-06-22
@Hitrou

ceh *p;                  // указатель типа ceh
p = new ceh[2];.    // присваивание значения на куче
p->set("Ivan", "moroz", 12); // обращение к функции-члену p[0]
void (ceh::*pf)();    // указатель типа функции-члена структуры ceh
pf = &ceh::show;. // присваивание значения указателю 
(p[0].*pf)();  // вызов функции-члена по указателю для нулевого
(p[1].*pf)();  // для первого, но возможно сначало надо для него через set установить значения полей

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question