Something i cannot get...

Hi,
Can someone explain to me the following error:
"no matching function for call to 'Student::Student(Student)'"
i got the message only in the return statement. (line 4)


1
2
3
4
5
Student StudentNode::getStudent(){
	Student s(*(this->student));
//	return s;
	return Student (*(this->student));
}


Here is Student:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Student {
public:
	Student(std::string ,int ,int);
	Student(Student&); //
	std::string getName() const; //
	int getID() const; //
	int getAverage() const; //
	void setName(std::string); //
	void setID(int); //
	void setAverage(int); //
	std::string format();
	virtual ~Student();
private:
    std::string name;
    int id, average;
};
Try changing

Student(Student&);

to

Student(const Student&);
Well, thank you very much. its work.

Can you tell me please what the differences?
What you had before, i.e. Student(Student&); is a copy constructor that takes a non-const reference. This is possible to have but there is a problem when it comes to temporary objects, namely that non-const references cannot bind to them. This means that the call to return Student (*(this->student)); was looking for a function that took in a Student because the copy-constructor you had could not be used in that situation. Making the copy constructor take in a const reference allowed it to handle the *(this->student) argument correctly.
Thank you very much!
Topic archived. No new replies allowed.