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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:26:08+00:00 2026-06-01T12:26:08+00:00

How does a copy constructor work in c++ Error 1 error C2064: term does

  • 0

How does a copy constructor work in c++

Error 1 error C2064: term does not evaluate to a function taking 1 arguments c:\users\thuan\dropbox\homework\css 342\lab2\lab2\lab2\lab2.cpp 26

#include "intset.h"

int main() {
IntSet object1;
IntSet object2(9);  

object1(object2); //error here

   return 0;
}
//constructor
IntSet::IntSet(int a, int b, int c, int d, int e)
{
numOfArray++;
int tempArray[] = {a, b, c, d, e};
size = determineHighest(tempArray) + 1; 

arrayPtr = new bool[size]();

for (int i = 0; i < MAXINITIALSIZE; i++)
{
    if (tempArray[i] == -1)
        continue;
    arrayPtr[tempArray[i]]= true;
}   
}
//copy constructor
IntSet::IntSet(const IntSet &intsetObject)
{
numOfArray++;
size = intsetObject.size;

arrayPtr = new bool[size];

for (int i = 0; i < size; i++)
{
    if (intsetObject.arrayPtr[i])
        arrayPtr[i] = intsetObject.arrayPtr[i];
}
}
  • 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-06-01T12:26:09+00:00Added an answer on June 1, 2026 at 12:26 pm

    After you declare

    InSet object1;
    

    the object named object1 exists (created via the default constructor). Copy constructor (just like a regular constructor) creates a new object. Since the object already exists, the expression object1(object2); cannot be a copy-constructor call. For that, you need to declare your variables like this:

    InSet object2(9);
    InSet object1(object2);
    

    If you wanted to copy object2 to the already existing object1, you will need an assignment operator (InSet& InSet::operator=(const InSet& other);)

    Note: The compiler error is telling you that the expression (object1(object2); is a function call expression: you will need to define the function call operator (void InSet::operator()(const InSet& obj)) to make it compile (the return type could be anything else, not just void, depending on your need.) If you define the function call operator, you turn your object into what is called a functor

    The compiler error (term does not evaluate to a function taking 1 arguments) is correct, but misleading wrt. to your problem (but there is no way for the compiler to know you wanted to use the copy constructor, instead of a function call)

    Note: On many compilers the expression

    InSet object2(9);
    InSet object1 = object2;
    

    also results in a call to the copy constructor (instead of default-constructing the object and then calling assignment operator on it), if available — this is a possible compiler optimization.

    Note: The declarations InSet object1; and InSet object2(9); are invalid if the only (regular) constructor you have is the one you listed, unless you have default values for the (regular) constructor’s parameters in the class definition (where the constructor is declared), which you did not include.

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

Sidebar

Related Questions

I have a class which does not have copy constructor or operator= overloaded. The
Does vector::operator= change vector capacity? If so, how? Does vector's copy constructor copy capacity?
I've been trying to modify the AuditTrail code so that it does not copy
Does glUniformMatrix4fv instantly copy data pointed to by the passed in pointer? If not
unique_ptr<T> does not allow copy construction, instead it supports move semantics. Yet, I can
If copy constructor is made private then in Case 1: No error, the compiler
Does the copy constructor of any std::container (specifically std::queue) containing object pointers call the
I'm writing a lua script, and one of the things it does is copy
Does anyone know of a way to copy mail attachments of a particular extention
Does anyone know of an easy way to copy a database from one computer

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.