Have a map with keys consisting of different types in C++

后端 未结 3 1112
别那么骄傲
别那么骄傲 2021-01-21 20:46

I currently am using a map in C++ and have a couple of values that are ints and booleans, though the majority of them are strings. I know in Java I could do something like this:

3条回答
  •  清歌不尽
    2021-01-21 21:08

    "but is there an Object equivalent in C++??"

    No, there isn't such thing in standard C++. c++-cli may provide something similar perhaps.

    "If not, is there any way I could properly have keys being a string, int, or boolean?"

    There's stuff like boost::variant or boost::any, but I'm not sure, if you could use them as a key in a std::map.

    Sounds a bit you're asking for a XY-Problem. Explain your actual use case please.

提交回复
热议问题