Explicit Call to a Constructor

前端 未结 5 1839
萌比男神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:00

    If you make a function that takes a reference to a object of your class, and you pass it another type other than your object the constructor of your class will convert that type to an object of your class. Any one argument constructor is treated as a conversion constructor. If you declare that constructor explicit, then passing a different type other than your object to that function will not convert it and the compiler will return an error

提交回复
热议问题