Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 42097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:17:05+00:00 2026-05-10T15:17:05+00:00

What does the explicit keyword mean in C++?

  • 0

What does the explicit keyword mean in C++?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:17:05+00:00Added an answer on May 10, 2026 at 3:17 pm

    The compiler is allowed to make one implicit conversion to resolve the parameters to a function. This means that the compiler can use constructors callable with a single parameter to convert from one type to another in order to get the right type for a parameter.

    Here’s an example with converting constructors that shows how it works:

    struct Foo {     // Single parameter constructor, can be used as an implicit conversion.     // Such a constructor is called "converting constructor".     Foo(int x) {} }; struct Faz {     // Also a converting constructor.     Faz(Foo foo) {} };  // The parameter is of type Foo, not of type int, so it looks like // we have to pass a Foo. void bar(Foo foo);  int main() {     // However, the converting constructor allows us to pass an int.     bar(42);     // Also allowed thanks to the converting constructor.     Foo foo = 42;     // Error! This would require two conversions (int -> Foo -> Faz).     Faz faz = 42; } 

    Prefixing the explicit keyword to the constructor prevents the compiler from using that constructor for implicit conversions. Adding it to the above class will create a compiler error at the function call bar(42). It is now necessary to call for conversion explicitly with bar(Foo(42))

    The reason you might want to do this is to avoid accidental construction that can hide bugs.
    Contrived example:

    • You have a MyString class with a constructor that constructs a string of the given size. You have a function print(const MyString&) (as well as an overload print (char *string)), and you call print(3) (when you actually intended to call print("3")). You expect it to print "3", but it prints an empty string of length 3 instead.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 102k
  • Answers 102k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Managed code is code that runs under a virtual machine,… May 11, 2026 at 8:13 pm
  • Editorial Team
    Editorial Team added an answer Check content size every time when you add text UITextView… May 11, 2026 at 8:13 pm
  • Editorial Team
    Editorial Team added an answer I`v found the solution. I had to add reference to… May 11, 2026 at 8:13 pm

Related Questions

I'm writing a program under MS Visual C++ 6.0 (yes, I know it's ancient,
I just stumbled across this bug in some legacy code: class MyAPIHandler { private:
I've done some Python but have just now starting to use Ruby I could
As the title says, does any Unix-like system ascribe a meaning to the SUID

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.