Why can't I construct a queue/stack with brace-enclosed initializer lists? (C++11)

前端 未结 3 2047
死守一世寂寞
死守一世寂寞 2021-01-31 18:52

Program 1:

#include 
#include 
#include 

int main(){

    //compiles successfully 
    std::vect         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 19:15

    std::queue and std::stack are not actually containers, they are so called container adaptors which uses a container (by default std::deque). Therefore you can not initialize it as other containers.

    Edit

    For a container to be able to use an initializer list, it must have a constructor taking an std::initializer_list as argument. The container adaptors don't do that. If it's deliberate or an oversight of the standards committee is up to anyones interpretation.

提交回复
热议问题