The code I want to work
#include <iostream>
using namespace std;
int main()
{
int v = 123;
auto doFn = [v](){ cout << "Hello World" << v << "\n"; };
auto noopFn = [v](){};
for (int i = 0; i < 4; ++i)
{
auto fn = (i & 1) ? doFn : noopFn;
fn();
}
return 0;
}
The error I get
main.cpp:14:27: error: operands to ?: have different types ‘main()::’ and ‘main()::’
14 | auto fn = (i & 1) ? doFn : noopFn;
| ~~~~~~~~^~~~~~~~~~~~~~~
I found this answer but if it's a solution I don't understand how to apply it.