How to initialize a CEvent member in the class declaration?

114 views Asked by At

CEvent has a single, explicit constructor, which accepts zero to four optional arguments.

Is there a way to initialize it as member in the class declaration? FooBar wouldn't need a written constructor at all if it were possible.

class FooBar {
    CEvent e1 = {FALSE, TRUE};
    CEvent e2 = (FALSE, TRUE);
    CEvent e3 = {(FALSE, TRUE)};
    CEvent e4 = CEvent(FALSE, TRUE);

None of these alternatives work.

1

There are 1 answers

0
Ron On

Use the direct list initialization syntax. Remove the = operator:

class FooBar {
    CEvent e1{ FALSE, TRUE };
    CEvent e2{ FALSE, TRUE };
    // etc
};