Vector that can have 3 different data types C++

后端 未结 4 1382
你的背包
你的背包 2020-11-29 10:10

I\'m trying to make a vector in C++ that can store 3 different data types. I do not want to use the boost library. Something like:

vector

        
4条回答
  •  北荒
    北荒 (楼主)
    2020-11-29 10:53

    you could use std::any, store your objects in the vector as any and when you pull them out use type() == typeid(mytype)

    https://en.cppreference.com/w/cpp/utility/any

    This is only for C++17 onwards though.

提交回复
热议问题