answersLogoWhite

0

Whenever the constructor's arguments must not be implicitly cast. For instance, if a constructor expects a float and you pass a double, the double will be implicitly cast to a float which may result in data loss due to narrowing. By declaring the constructor explicit, you must explicitly cast the double to a float, making it clear to the reader that narrowing is an acceptable consequence.

struct A {

explicit A (float);

};

void g ()

{

float f {42.0f};

double d {42.0};

A a (f); // ok -- explicit float

A b (d); // error -- implicit cast from double to float is not permitted

A c (static_cast<float> (d)); // ok -- explicit cast, narrowing is permitted

}

Note that all explicit casts should be done using named casts rather than C-style casts. This ensures the code stands out like the sore-thumb that it is because explicit casts are often a sign of poor design. When you finally come to your senses, named casts are much easier to locate and rectify.

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

What are explicit messages?

The word explicit is often used in the sense of sexually explicit.


What part of speech is explicit?

The word &quot;explicit&quot; is an adjective. It is used to describe something that is clear, direct, and unambiguous.


Spanish word for builder?

constructor


What word is used by medieval scribes to indicate the end of a book?

Explicit


What is a good sentence for explicit?

A good sentence for explicit?.... "The women left EXPLICIT instructions explaining which medicines should be given to which cats." Random, but I think it demonstrates good use of the word.


What is the Root word of explicit?

'Explicit' is a Latin word meaning 'he, she, or it explains'.


Is smut a bad word?

&quot;Smut&quot; can be considered a vulgar or derogatory term when used to describe explicit or pornographic material. It is often used in a negative context to refer to sexually explicit content.


What is an explicit message?

An explicit message would be one that is clear and unambiguous.Here are some examples from users:My friend Bob once went to the store to get some eggs.That is a nice purple shirt.Note: although you hear the word used with music in a certain way, the word "explicit" just means clear and obvious. It doesn't always mean "sexually explicit" or "potentially offensive" as it is used in music labeling.


Is constructor a verb?

A verb is a doing word. This is a noun, which is a thing.


What is a sentence using the word explicit?

They were explicit in their criticisms of the plan. Explicit nudity or sexual activity is normally classed as pornography.


What does the biblical Greek word tekton mean?

&tau;&#941;&kappa;&tau;&omega;&nu; [tekton] is the builder / constructor / mason&alpha;&rho;&chi;&iota;&tau;&#941;&kappa;&tau;&omega;&nu; = architect is the prime builder / constructor, the leader of a group of builderstectonic = masonic


Can you give me a sentence for the word explicit?

The new teacher was fired for using explicit language around the students.