Reputation: 69
I have this method I'm trying to complete, which when completed should construct a limited list of choices from the options vector passed into the method:
> int Program::SelectFromMenu(int x, int y, std::vector<std::string> options);
For instance, if I wanted to have a menu selection in a bank system, I could add these three strings to my options vector, then the method would display these three choices to the user:
<"Withdraw", "Deposit", "Statement">
They pick an option, their decision will call a method. Easy right? I've coded that part already. The problem is getting the vector itself into the method:
In an ideal world, I'd create a temporary vector like this, and use it as an argument:
SelectFromMenu(2, 4, <"Withdraw", "Deposit", "Statement">);
but I'm unable to do this. What other ways am I able to achieve passing a vector into the method? I mean, I could make a method that constructs the vector from strings I pass in, but that seems like the wrong way to do this.
Any help would be appreciated, thanks.
Upvotes: 3
Views: 1682
Reputation: 42858
You could use a braced-init-list:
SelectFromMenu(2, 4, {"Withdraw", "Deposit", "Statement"});
Upvotes: 2