Quick A: By having your constructor take an initializer_list<> of the appropriate type.
Today on StackOverflow:
Constructor similar to
std::maporstd::vectorin a classI'm creating a class and I want to know how to create a constructor similar to the
std::maporstd::vectorstyle.std::map<std::string, std::string> map = { {"foo", "bar"}, {"biz", "buz"}, {"bez", "boz"} };The difference is that I don't want my class to ask for types that wants to accept, just like
std::mapdoes.std::map<std::string, std::string>I want my class to accept that style of arguments:
{ {"foo", "bar"}, {"biz", "buz"}, {"bez", "boz"} };But with defined type.
(std::string, Typer)The '
Typer' is a class that I will insert as value on thestd::map.Thank you.

Add a Comment
Comments are closed.