1. By Constructor Conversion :
See this situation .
Output :
Constructor B called
Hi inside Function
--------------------------------------------------------------------------------
Preventing constructor conversion.
This Behaviour of automatic calling of constructor . can be stopped if constructor is explicit.
Explicit Constructor: Constructor with explicit keyword.It prevents compliler from performing implicit (Unexpected) type conversions.
After this func (a); will not get compiled .
Output:Compliation Fails
auotTypeConversion.cpp: In function `int main()':
auotTypeConversion.cpp:18: error: conversion from `A' to non-scalar type `B' requested
2. Operator Conversion :
OUTPUT:
inside conversion operator B--> A
inside A constructor i=10
Function call
Very nice blog, Thank you for providing good information.
ReplyDeletepython training in bangalore | python online Training
artificial intelligence training in bangalore | artificial intelligence online training
machine learning training in bangalore | machine learning online training
uipath-training-in-bangalore | uipath online training
blockchain training in bangalore | blockchain online training
aws training in Bangalore | aws online training
data science training in bangalore | data science online training
hadoop training in bangalore | hadoop online training
iot training in bangalore | iot online training