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

  • Home
  • SEARCH
  • 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 3489448
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:23:49+00:00 2026-05-18T11:23:49+00:00

I am reviewing for my final, and I cannot figure out why this question

  • 0

I am reviewing for my final, and I cannot figure out why this question is what it is.

Assume the following class declaration:

class Testing {
 public:
       Testing(int n);
       void Show(const Testing& w, int a = 10);
       int value;
 private:
       int DoThis();
 };

Assume the following lines of code are attempting in a main() program, and that x is of type Testing and has been propertly created.

x.Show(18); Legal or Illegal

The answer is legal, I understand that the 2nd parameter is not needed because of the = 10,but since 18 is not of type Testing isn’t that an invalid parameter?

  • 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. Editorial Team
    Editorial Team
    2026-05-18T11:23:50+00:00Added an answer on May 18, 2026 at 11:23 am

    Testing has a non-explicit constructor that takes an int. Therefore, an int can be implicitely converted to a Testing by constructing a temporary object.

    Since Show takes a const Testing & (and not just a Testing &), you can pass a temporary to it. Finally, the second parameter is optional, so you don’t have to specify a value for that.

    This whole mechanism is what allows you do this, by the way:

    void f(const std::string &str);
    // ...
    f("Hello");
    

    Here, "Hello" is of type const char (&)[6], which decays to a const char *, but you can construct a std::string from a const char *, thus permitting the use of a const char * where a std::string parameter is needed.

    Keep in mind that this constructs a temporary, and therefore is only valid for parameters that are passed by value or by const reference (it will fail for references). Also, the constructor must not be marked as explicit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reviewing for a class, and this is an old question: I need to
I have been reviewing algorithms, this is question from Anany Levitin's algo book.. You
I was reviewing some code and I came across this: public static doSomething(String myString,
After reviewing this answer and given the extension method: public static bool IsIn<T>(this T
I was just putting some thought into different languages (as I'm reviewing for final
When reviewing, I sometimes encounter this kind of loop: i = begin while (
When reviewing our codebase, I found an inheritance structure that resembles the following pattern:
This was originally going to be a question about how to implement this because
In reviewing this post Android: I want to shake it , the highest rated
After reviewing this blog by Kirill Osenkov (How to create a generic List of

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.