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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:38:22+00:00 2026-05-26T19:38:22+00:00

This is my source file written in C++. #include<string> #include<sstream> #include Lecture.hpp #include <iostream>

  • 0

This is my source file written in C++.

#include<string>
#include<sstream>
#include "Lecture.hpp"
#include <iostream>

using namespace std;


Lecture::Lecture() {
  capacity=5;
  log = new int[capacity];
  used = 0;
}

/*
 * The following is copy constructor.
 */
Lecture::Lecture(Lecture& orig) {
   copy(&orig);

}

/*
 * This is an empty destructor
 */
Lecture::~Lecture() {
    // dereference dynamic memory
}

 Lecture & Lecture:: operator=(Lecture & other){
     this->copy(&other);
     return *this;
 }
 /*
  * Copy method.
  */
 void Lecture::copy(Lecture &other){    
     if(&other != this){
         capacity = other.capacity;
         log = new int[capacity];
         used = other.used;
         for(int x = 0; x < used; x++){
            log[x]= other.log[x]; 
         }
     }
 }

string Lecture::getLogs() {
  ostringstream ans;
  ans << "[";
  for (int i=0; i<used-1; ++i) {
    ans << log[i] <<", ";
  }
  if (used>0) 
    ans << log[used-1] << "]";
  else
    ans << "empty log]";
  return ans.str();
}

void Lecture::addLogEntry(int b) {
   if (used==capacity) {
    capacity *= 2;
    int* temp= new int[capacity];
    for (int i=0; i<used; ++i) {
      temp[i]=log[i];
    }
    delete[] log;
    log=temp;
  }
  log[used]=b;
  used++;
}

From copy constructor and from overloaded = operator function I am trying to invoke copy() function. It gives me the following error:

Lecture.cpp: In copy constructor `Lecture::Lecture(Lecture&)':
Lecture.cpp:26: error: no matching function for call to `Lecture::copy(Lecture*)'
Lecture.hpp:21: note: candidates are: void Lecture::copy(Lecture&)
Lecture.cpp: In member function `Lecture& Lecture::operator=(Lecture&)':
Lecture.cpp:38: error: no matching function for call to `Lecture::copy(Lecture*)'
Lecture.hpp:21: note: candidates are: void Lecture::copy(Lecture&)
make[2]: Leaving directory `/cygdrive/g/Aristotelis/C++/Assessment_2'
make[1]: Leaving directory `/cygdrive/g/Aristotelis/C++/Assessment_2'
make[2]: *** [build/Debug/Cygwin-Windows/Lecture.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2 

For some reasons at copy method it expects a pointer. Why is that?
This is my header file:

#ifndef LECTURE_HPP
#define LECTURE_HPP

#include<string>
using namespace std;

class Lecture{ 

 public : 
  Lecture();                 // default constructor
  Lecture(Lecture &other);  // copy constructor
  string getLogs();
  void addLogEntry(int);
  void copy(Lecture &other); // copy method
  ~Lecture();                // destructor
  Lecture& operator=(Lecture& other); // overloading of '='

 private: 
  int* log;
  int used;
  int capacity;



};

#endif  /* LECTURE_HPP */

This is main method:

#include<iostream>
#include<string>
//#include "University.hpp"
#include <cmath>
#include <cstdlib>



using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {


  Lecture c1;

  cout << "Information of c1: " <<c1.getLogs() << endl;

  c1.addLogEntry(20);

  cout << "Information of c1: " <<c1.getLogs() << endl;

  Lecture c2=c1;

  cout << "Information of c2: " <<c2.getLogs() << endl;

  Lecture c3;
  c3=c1;

  cout << "Information of c3: " <<c3.getLogs() << endl;

  c1.addLogEntry(-4);
  c2.addLogEntry(10);

  cout << "-----------------------------------------------"<< endl;

  cout << "Information of c1: " <<c1.getLogs() << endl;
  cout << "Information of c2: " <<c2.getLogs() << endl;
  cout << "Information of c3: " <<c3.getLogs() << endl;


    return 0;
}

What might be the problem?

  • 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-26T19:38:23+00:00Added an answer on May 26, 2026 at 7:38 pm

    Because you are passing a pointer:

    Lecture::Lecture(Lecture& orig) {
       copy(&orig);  // The & here is taking the address of orig (so remove it!)
    }
    

    [Sidenote 1: Unless you have a very good reason, your copy constructor, etc. should prefer to take a const ref over a non-const ref.]

    [Sidenote 2: See this question for the idiomatic way to implement copy-constructor and copy-assignment operators in C++.]

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

Sidebar

Related Questions

I'm working this source code: #include <string> #include <vector> #include <iostream> #include <istream> #include
Using this file as source, I have a situation where I need to retrieve
This obviously requires the source file to be under source control. I would ideally
Given a (source) patch file, what's the easiest way to apply this patch on
I'm using a MediaElement with this source: http://origin-community.ministryofsound.com/asx/radio/mosRadio.asx When I open it with Windows
I am modifying a CMake file of an existing open source project written in
I have a CMakeLists.txt file that looks like this: add_executable(exec1 exec1.c source1.c source2.c source3.c)
Consider this source: public partial class FormTest : Form { private Test test {
like this (source: photoshopessentials.com )
I have this source code from 2001 that I would like to compile. It

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.