0

I am trying to conditionally initialize a structure but I cannot seem to find the source of the problem.

The code that I have is

struct CalculatorPair
  {
    using Calculator = std::function<std::optional<float>(Obj&, int)>;

    CalculatorPair(const Calculator & init, const Calculator & fin) : initial(init), final(fin)
    {
    }

    Calculator initial;
    Calculator final;
  };

as a helper structure and then I want to initialize it like this

CalculatorPair calculator = getCondition() ? { computeInitialWay1, computeFinalWay1 } : { computeInitialWay2, computeFinalWay2 };

But I keep getting messages from the compiler saying "syntax error: missing ';' before '{'" which I don't think is the problem.

lnlyprog
  • 23
  • 5
  • 1
    It cannot deduce type from `{}`. You need `Type{initilizer}` in both places – Yksisarvinen Dec 22 '22 at 11:05
  • 1
    `{ computeInitialWay2, computeFinalWay2 }` is an initializer list only if it is used for immediate initialization. It's not a valid expression anywhere else. – molbdnilo Dec 22 '22 at 12:06

0 Answers0