Calling constructors in c++ without new

前端 未结 7 1533
离开以前
离开以前 2020-12-04 05:20

I\'ve often seen that people create objects in C++ using

Thing myThing(\"asdf\");

Instead of this:

Thing myThing = Thing(\"         


        
相关标签:
7条回答
  • 2020-12-04 06:09

    Ideally, a compiler would optimize the second, but it's not required. The first is the best way. However, it's pretty critical to understand the distinction between stack and heap in C++, sine you must manage your own heap memory.

    0 讨论(0)
提交回复
热议问题