Are there any cases where it is incorrect to replace push_back with emplace_back?

前端 未结 6 1453
不思量自难忘°
不思量自难忘° 2021-01-02 09:44

Can I break a valid C++03 program by replacing std::vector::push_back with emplace_back and compiling it with C++ 11 compiler? From reading e

6条回答
  •  粉色の甜心
    2021-01-02 10:33

    int main() {
    std::vector().push_back(0);
    std::vector().emplace_back(0); 
    }
    

    Give struct constructor in emplace_back i.e The above code will be like this

    int main() {
    std::vector().push_back(0); 
    std::vector().emplace_back(S(0)); 
    }
    

提交回复
热议问题