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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:40:07+00:00 2026-05-26T13:40:07+00:00

Im learning C++ and I ran into something strange that I couldn’t find any

  • 0

Im learning C++ and I ran into something strange that I couldn’t find any info on in my C++ book, or on the web. The code below is simply a test of the conversion constructor: Test(int). testFunction gets an int where a Test object is expected, and the conversion constructor is used to create a Test object to send to the function. This works as expected.

#include <iostream>
using namespace std;

class subClass {
public:
  subClass(int);
  subClass(subClass&);
};

subClass::subClass(int i) {};
subClass::subClass(subClass& i) {};

class Test {
public:
  Test(const Test&);
  Test(int);
  subClass sub;
};

Test::Test(const Test &)
  : sub(1) {};

Test::Test(int in)
  : sub(1) {};

void testFunction(Test in) {
  cout << "testfunction\n";
};

int main () {

  testFunction(4);
}

However, If i remove the copy constructor Test(const Test&) from the Test class I get the error message shown below. But the copy constructor is never used, so why is it needed?

example.cpp: In function `int main()':
example.cpp:32: error: no matching function for call to `Test::Test(Test)'
example.cpp:13: note: candidates are: Test::Test(Test&)
example.cpp:24: note:                 Test::Test(int)
example.cpp:32: error:   initializing argument 1 of `void testFunction(Test)' from result of `Test::Test(int)'

Additional info:
I noticed that either removing the copy constructor from the subclass or passing the argument by reference to testFunction makes it possible to compile the function without Test’s copy constructor. Im using the gnu g++ compiler in cygwin.

  • 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-26T13:40:07+00:00Added an answer on May 26, 2026 at 1:40 pm

    Because:

    void testFunction(Test in)
    

    You’re passing a Test object by value which invokes the copy constructor.

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

Sidebar

Related Questions

I'm learning jQuery by trying to understand other people's code. I ran into this:
I'm learning ObjectiveC and ran into a problem relating to introspection. Basically, I'm looping
I am learning JQuery, and I have ran into an odd issue. I made
Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
I am learning how to develop iPhone applications and I ran into an interesting
I recently started learning 0MQ . Earlier today, I ran into a blog, Python
in the process of creating a WCF service I ran into a term that's
I am learning mysql and ran into a problem with 'mysql.proc' missing when trying
I'm working on learning C# and I've ran into a problem with an example
I am in the process of learning PHP and I ran into a snag,

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.