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 3975768
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:43:28+00:00 2026-05-20T04:43:28+00:00

Heres the link to code and the error I dont understand why the line

  • 0

Heres the link to code and the error

I dont understand why the line return (const C&)cc; doesnt work.

Heres a paste of code and error

#include <stdio.h>

class C 
{
public:
    int i;
    explicit C(const C&)   // an explicit copy constructor
    {
        printf("\nin the copy constructor");
    }
    explicit C(int i )   // an explicit constructor
    {
        printf("\nin the constructor");
    }

    C()
    {
        i = 0;
    }
};

class C2
{
public:
    int i;
    explicit C2(int i )   // an explicit constructor
    {
    } 
};

C f(C c)
{   // C2558
//    c.i = 2;
//    return c;   // first call to copy constructor
C cc;
return (const C&)cc;
}

void f2(C2)
{
}

void g(int i)
{
//    f2(i);   // C2558
    // try the following line instead
     f2(C2(i));
}

int main()
{
    C c, d;
    d = f(c);   // c is copied
}

Output:

In function ‘C f(C)’: Line 36: error:
no matching function for call to
‘C::C(const C&)’ compilation
terminated due to -Wfatal-errors.

  • 1 1 Answer
  • 4 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-20T04:43:29+00:00Added an answer on May 20, 2026 at 4:43 am

    Examples of calling the explicit copy-constructor:

    • http://ideone.com/bV4S7
    • http://ideone.com/G0OYi

    Of course, pass-by-value and return-by-value always call the copy constructor implicitly, so declaring the copy constructor explicit will prevent this (not necessarily a bad thing).

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

Sidebar

Related Questions

Here is some code I don't understand, but I know it opens the link
Here is link where i got a code for web-page content fetching. But i
I'm learning by reading this tutorial: Link Here's the code: <?php require_once 'Zend/Loader.php'; class
Heres the link: DAMNIE6TOHELL As you can see if viewed in glorious 'IE6-o-color', the
Heres my link: http://tinyurl.com/6j727e If you click on the link in test.php, it opens
Heres my link ( BE WARNED, its got autoplay audio - sorry...!) link text
Heres my saga - I'm trying to link http://www.example.com to my shopping cart on
In FF this border radius doesn't seem to want to work. Editable link here.
If i run the link in ieTester, in ie7 pops up a js error
I think I am starting to understand how to link functions written in C/C++

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.