Explicit Call to a Constructor

前端 未结 5 1882
萌比男神i
萌比男神i 2021-02-04 16:16

I know the concept that we can call the Constructor both Explicitly and Implicitly, and i have tested both the scenarios(generally till now my all purp

5条回答
  •  忘了有多久
    2021-02-04 17:06

    Calling constructors explicitly allow you to construct object with arguments, rather than using the default constructor.

    class Foo
    {
      public:
        Foo() {}
        Foo(int bar) : mBar(bar) {}
      private:
        int mBar;
    }
    
    Foo f;    // Implicitly constructed with default constructor.
    Foo f(7); // Explicitly constructed with argument for 'bar'
    

提交回复
热议问题