Wednesday, March 6, 2019

move - Application of C++ Explicit Constructor

An explicit constructor is a function that does not get called in implicit type conversion.



For example:



class A {

A( int a ) {}
};

void foo( A a ) {}


Here is totally legal to call foo(1) or use any variable of type int or that can be implicitly converted to an int. This is not always desirable, as it would mean that A is convertible from an integer, instead of being defined with an integer. Adding the explicit would avoid the conversion and, hence, give you a compilation error.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...