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

前端 未结 3 1315
谎友^
谎友^ 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

    The standard's definition of copy-assignment operator is (section [class.copy]):

    A user-declared copy assignment operator X::operator= is a non-static non-template member function of class X with exactly one parameter of type X, X&, const X&, volatile X& or const volatile X&.

    But the X& and volatile X& variants may not be compatible with containers assuming an assignment can be made from an r-value RHS.

    NOTE: Passing by value, e.g. X::operator=(X) is a fundamental part of the copy-and-swap idiom.

提交回复
热议问题