Can I call a constructor from another constructor (do constructor chaining) in C++?

前端 未结 15 2320
暖寄归人
暖寄归人 2020-11-22 01:27

As a C# developer I\'m used to running through constructors:

class Test {
    public Test() {
        DoSomething();         


        
15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 01:54

    When calling a constructor it actually allocates memory, either from the stack or from the heap. So calling a constructor in another constructor creates a local copy. So we are modifying another object, not the one we are focusing on.

提交回复
热议问题