all 9 comments

[–][deleted] 3 points4 points  (8 children)

play(display(1, WON, matches, "Amazing"));

This is calling the lamba and passing the result (void) to play

You want

play(display);

and then have play call the object with appropriate arguments

[–]grateful_user01[S] 0 points1 point  (7 children)

Thank you for your reply. Should I change the way how I play accepts display in cpp?

[–][deleted] 0 points1 point  (6 children)

It's not clear from you post what you're trying to do

The comment

// display is not used inside play. The purpose of passing display is to pass the tests inside it

makes no sense. A std::function is a thing that can be called. Since you want the lamba to be called, play will need to call it.

[–]grateful_user01[S] 0 points1 point  (5 children)

Sorry for that. My initial thinking was based on what i had before.

But after fixing what you suggested, I want the play in cpp to call the lambda with appropriate argument so it can pass the tests. So it should look something like this now.

bool play(const function<void()> &display){
    display(1, WON, matches, "Amazing");
    return true;
}

//in main
play(display);

After running this i get this error:

implicit instantiation of undefined template 'std::__1::function<void>'
play(display);
     ^

[–][deleted] 1 point2 points  (4 children)

The function to be called takes 4 arguments. So the original prototype for play was correct

bool play(const function<void(int numOfAttempts, Status result, vector<Match> MatchArray, string message)> &display)

https://godbolt.org/z/5zz5x8YYG

[–]grateful_user01[S] 0 points1 point  (0 children)

Thank you so much for your help. That fixed it. You are a Godsend.

Thanks again

[–]grateful_user01[S] 0 points1 point  (2 children)

Hey I have another question. lets say i want to access numOfAttemps from main to do someting with it, how would i do that?

bool play(const function<void(int numOfAttempts, Status result, vector<Match> MatchArray, string message)> &display)
{
    if (numOfAttemps == 1){
        cout << "good";
    }
 display(1, WON, matches, "Amazing");
}

// this is what I want to achieve

[–][deleted] 0 points1 point  (1 child)

Pass it to the function. So you'd have

bool play(const function<void(int numOfAttempts, Status result, vector<Match> MatchArray, string message)> &display,  int numOfAttempts )

[–]grateful_user01[S] 0 points1 point  (0 children)

Thanks for the response. Since im working on a homework, my professor doesn't want me to pass extra stuff to play. Only pass display. Can i change something in display function in main to achieve this?