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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:46:56+00:00 2026-05-27T08:46:56+00:00

I am writing c++ program. This is Student class: #include Student.hpp #include Home.hpp #include

  • 0

I am writing c++ program. This is Student class:

#include "Student.hpp"
#include "Home.hpp"
#include <string>

using namespace std;
/*
 * This is default constructor
 */
Student::Student(){

}
/*
 * This is copy constructor
 */
Student::Student(const Student& orig) {
   copy(orig);// invokes deep copy method
}
/*
 * This is a destructor
 */
Student::~Student() {
}

/*
 * This is operator = overloading method.
 * 
 * @param student. It is a reference to student class
 * @return Returns pointer to current class
 */
Student & Student::operator=(Student & student){
   if(this != &student){ // checks if they are referencing the same class.          
      copy(student);
   }
   return *this;
}

/*
 * This is setter
 * 
 * @param x The random integer number
 */
void Student::setValue(int x){
   data = x;
}

/*
 * The getter.
 * 
 * @return Returns integer digit
 */
int Student::getValue(){
   return data; 
}

/*
 * The copy method. It makes a deep copy of a current class.
 * 
 * @param orig. It contains a reference to student class
 */
void Student::copy(const Student &orig){
    if(this != &orig){
    // makes a copy of data member
       data = orig.data;      

    }
}

This is snippet of main method:

Student * array = new Student[objectSize];
    cout << "\nOriginal array of Student type: "; 
    int i = 0; 
    for(int x = objectSize; x > 0; x--){
      array[i].setValue(x);

      cout << array[i] << " "; // prints the contents of original Student type array
       i++;
    }

    defaultObject.addition(array, objectSize); // invokes function to sort array of Student type

This is header file:

#include <string>

using namespace std;

#ifndef STUDENT_HPP
#define STUDENT_HPP

class Student {

    friend ostream& operator<< (ostream& os, const Student& study){// overloads << operator for Student class      
        os << study.data; // the data you output       
    return os; 
   }
public:  
    Student(); // default constructor
   // Student(int data);// overloaded constructor
    Student(const Student& orig);// copy constructor
    virtual ~Student();// destructor
    Student & operator=(Student& student); // overloads = operator
    void setValue(int x);// setter
    int getValue();// getter
    void copy(const Student &orig);// copy method


    friend bool operator> (Student &first, Student &second){// overloads greater operator
       return first.data > second.data;
   }    

private:
    int data;// data member for storing Student's class contents
};

#endif  /* STUDENT_HPP */

The problem is that when I comment this line Student(int data); in header file the program throws this error:

Student.hpp: In function `std::ostream& operator<<(std::ostream&, const Student&)':
In file included from Student.cpp:12:
Student.hpp:21: error: no match for 'operator<<' in 'os << study->Student::data'
Student.hpp:20: note: candidates are: std::ostream& operator<<(std::ostream&, const Student&)
make[2]: *** [build/Debug/Cygwin-Windows/Student.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 4s)

In fact that overloaded constructor at Student.cpp file is not defined, but if declaration is there the program on NetBeans works, though on Linux terminal it throws the mentioned error.

  • 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-27T08:46:57+00:00Added an answer on May 27, 2026 at 8:46 am
    error: no match for 'operator<<' in 'os << study->Student::data'
    note: candidates are: std::ostream& operator<<(std::ostream&, const Student&)
    

    You are asking it to write an int to the stream. Note the very short list of possible candidates, the compiler says it only knows how to write a Student to the stream. That used to be possible before you commented the Student(int) constructor. That constructor can be used to convert an int to a Student. That will come to a very poor end at runtime when the stack blows up, but that’s beside the point.

    You are missing an #include for a header that declares an operator<< that allows an int to be written to the stream. Not actually sure which one that might be, I don’t like streams. Not an issue, homework questions shouldn’t have real answers 🙂

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

Sidebar

Related Questions

Writing a python program, and I came up with this error while using the
I'm writing a program using python 2.6 and pyqt4. I want this program to
i was writing a program and using double.Try Parse to check if a string
I am writing c++ program. This is snippet of main method: Student * array
I am writing this java program to find all the prime numbers up to
I'm actually writing an MPI program. This is a basic client / server pattern.
I've run into this while writing a Traveling Salesman program. For an inner loop,
I'm writing a program (for Mac OS X, using Objective-C) and I need to
I'm a university student learning programming. For practice I'm writing a blackjack program. I'm
I am writing a program in C# on Ubuntu with Mono. This program takes

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.