Unexpected compilation problem with g++ -std=c++0x

前端 未结 3 1318
谎友^
谎友^ 2021-02-15 17:28

I have some compilation problems pushing back elements of type T to a vector when compiling with g++ -std=c++0x.

This is a minimal example:

#include <         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-15 17:45

    I'm quite sure this is a safety feature. Types with a copy-assignment operator (or a copy constructor) that may mutate the right-hand side are not safe to use in standard containers - an example of this is (the now deprecated) std::auto_ptr which will break horribly if stored in a container.

    The old C++03 library implementation permitted such unsafe code, but apparently they implemented a compile-time check in the C++0x version -- probably in conjunction with move-enabling the containers.

提交回复
热议问题