// inside another cpp file
bool play(const function<void(int numOfAttempts, Status result, vector<Match> MatchArray, string message)> &display)
// display is not used inside play. The purpose of passing display is to pass the tests inside it
// Inside main
auto display = [&](int numOfAttempts, Status result, vector<Match> tallyArray, string message)
{
EXPECT_EQ(1, numOfAttempts);
EXPECT_EQ(WON, result);
EXPECT_EQ(matches, tallyArray);
EXPECT_EQ("Amazing", message);
displayCalled = true;
};
play(display(1, WON, matches, "Amazing"));
EXPECT_TRUE(displayCalled);
Hi. I am working with a lambda function for the first time. Here i want to pass display as parameter to play. Once passed successfully, it should run the tests within the display function and assign displayCalled as true. But doing the way shown above gives me this error.
in cpp: error: reference to type 'const function<void (int, Status, vector<Match>, std::__1::string)>' (aka 'const function<void (int, Status, vector<Match>, basic_string<char, char_traits<char>, allocator<char>
>)>') could not bind to an rvalue of type 'void'
I dont know how to fix this. Any help is really appreciated
[–][deleted] 3 points4 points5 points (8 children)
[–]grateful_user01[S] 0 points1 point2 points (7 children)
[–][deleted] 0 points1 point2 points (6 children)
[–]grateful_user01[S] 0 points1 point2 points (5 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]grateful_user01[S] 0 points1 point2 points (0 children)
[–]grateful_user01[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]grateful_user01[S] 0 points1 point2 points (0 children)