Data type conversion in C++-Part a/c

Data conversion-:

In c++, data conversion is performed.

It is performed implicitly and explicitly.

Implicit means direct.

Explicit means indirect.

In c++, assignment operator is used for implicit conversion.

For eg;

float x=3.14;

m=x; //then x becomes integer

We need explicit conversions for the following types of cases.

  1. Conversion from
  2. Basic to class type
  3. Class to basic type
  4. One class type to another class type

This will be divided into 3 parts.

The first part is obviously a).

I can guarantee that this blog is easy to follow because I have researched many books, many experts, many software development books before writing this concept.

I want you to focus 4 min for this, and your concept will be crystal clear.

“don’t waste your time using facebook or any wrong maza”

Maza=distraction (for non-indians)

Conversion from basic type to class type

for conversion from basic type to class type

we use one argument parameterized constructor.

And argument of basic type is passed in an parameterized constructor.

I want to repeat it again…we use one argument parameterized constructor….

And that argument inside one argument parameterized constructor is the basic type argument…that needs to be converted to class type.

Write an example program to show the concept of conversion from basic type to class type.

The thing that we are going to do in the program is that, we want to convert a basic type say int, float into class type, i.e anything …as class can be made for anything.

The basic map in your mind should be of this.

As I have already said that you need an one argument parameterized constructor, there will be constructor with one argument, inside the class.

And that is the key thing in this problem.

The next door’s key to learn this concept properly is how we overload operators to convert these data types( in the main function).

We simply do

class type data=basic type data..

The above expression literally means, from basic type data to class type data.

Now, let’s see the code.

Output-:

hr= 1
min= 1
second= 35

There is nothing left to explain about this more.

Practice this program in your copy.

If you want to get 100% of the time you spend in this website, then you should take a copy and write the code in your copy.

Bye, Bye with a quote-:

“What is more important for you? Your laziness, fear, problems or the thing that you want to get in your life? Decide them now”

Leave a Comment

Your email address will not be published. Required fields are marked *

Do NOT follow this link or you will be banned from the site! Scroll to Top