What breaking changes are introduced in C++11?

后端 未结 9 1789
陌清茗
陌清茗 2020-11-22 14:34

I know that at least one of the changes in C++11 that will cause some old code to stop compiling: the introduction of explicit operator bool() in the standard l

9条回答
  •  执念已碎
    2020-11-22 15:24

    How is the introduction of explicit conversion operators a breaking change? The old version will still just be as "valid" as before.

    Yes, the change from operator void*() const to explicit operator bool() const will be a breaking change, but only if it is used in a way that is wrong in and out of itself. Conforming code won't be broken.

    Now, another breaking change is the banning of narrowing conversions during aggregate initialization:

    int a[] = { 1.0 }; // error
    

    Edit: Just rememberer, std::identity will be removed in C++0x (see the note). It's a convenience struct to make types dependent. Since the struct really doesn't do much, this should fix it:

    template
    struct identity{
      typedef T type;
    };
    

提交回复
热议问题