Don't understand c++ error about overloaded functions [on hold]
up vote
-1
down vote
favorite
I have a student struct:
struct Student {
std::string name;
int age;
double finalGrade;
std::string toString() {
return "Name: " + name + "nAge: " + std::to_string(age) + "nFinal Grade: " + std::to_string(finalGrade);
}
};
And I want to write my own comparison function to use with the sort() method.
bool compareByName(const Student &a, const Student &b) {
return (a.name).compare(b.name) > 0;
}
I'm getting an 'overloaded function differs only by return type from 'void compareByName(const Student &,const Student &)' error.
c++
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4 Nov 13 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4
If this question can be reworded to fit the rules in the help center, please edit the question.
|
show 2 more comments
up vote
-1
down vote
favorite
I have a student struct:
struct Student {
std::string name;
int age;
double finalGrade;
std::string toString() {
return "Name: " + name + "nAge: " + std::to_string(age) + "nFinal Grade: " + std::to_string(finalGrade);
}
};
And I want to write my own comparison function to use with the sort() method.
bool compareByName(const Student &a, const Student &b) {
return (a.name).compare(b.name) > 0;
}
I'm getting an 'overloaded function differs only by return type from 'void compareByName(const Student &,const Student &)' error.
c++
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4 Nov 13 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4
If this question can be reworded to fit the rules in the help center, please edit the question.
4
You seem to have another method elsewhere with the signaturevoid compareByName(const Student &,const Student &), which only differs from the other version by its return type, which isn't allowed. Do you need the other version? It seems odd for a comparing function to have a void return type.
– Carcigenicate
Nov 10 at 19:04
@Carcigenicate I had a void return type in my function declaration.. Thanks for pointing me in the right direction
– whelanevan6
Nov 10 at 19:06
1
Strange you would discover the error now, since the error message you posted is stating exactly what @Carcigenicate pointed out.
– PaulMcKenzie
Nov 10 at 19:09
@PaulMcKenzie I misinterpreted the error and didn't even remember writing the declaration
– whelanevan6
Nov 10 at 19:11
@whelanevan6 -- often the deluge of error messages and notes that you get when you mess up a template contains exactly the information you need to find the problem. You have to wade through it, but for this example, I'm guessing that somewhere shortly after the error message itself there were a couple of notes that showed where this function was defined and where the conflicting one was declared. Everything from the first "error" message to the next "error" message is discussion about what the first error message means.
– Pete Becker
Nov 10 at 19:23
|
show 2 more comments
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I have a student struct:
struct Student {
std::string name;
int age;
double finalGrade;
std::string toString() {
return "Name: " + name + "nAge: " + std::to_string(age) + "nFinal Grade: " + std::to_string(finalGrade);
}
};
And I want to write my own comparison function to use with the sort() method.
bool compareByName(const Student &a, const Student &b) {
return (a.name).compare(b.name) > 0;
}
I'm getting an 'overloaded function differs only by return type from 'void compareByName(const Student &,const Student &)' error.
c++
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have a student struct:
struct Student {
std::string name;
int age;
double finalGrade;
std::string toString() {
return "Name: " + name + "nAge: " + std::to_string(age) + "nFinal Grade: " + std::to_string(finalGrade);
}
};
And I want to write my own comparison function to use with the sort() method.
bool compareByName(const Student &a, const Student &b) {
return (a.name).compare(b.name) > 0;
}
I'm getting an 'overloaded function differs only by return type from 'void compareByName(const Student &,const Student &)' error.
c++
c++
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Nov 10 at 19:01
whelanevan6
141
141
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
whelanevan6 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
put on hold as off-topic by Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4 Nov 13 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4 Nov 13 at 12:03
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Alan Birtles, πάντα ῥεῖ, Jesper Juhl, Andras Deak, E_net4
If this question can be reworded to fit the rules in the help center, please edit the question.
4
You seem to have another method elsewhere with the signaturevoid compareByName(const Student &,const Student &), which only differs from the other version by its return type, which isn't allowed. Do you need the other version? It seems odd for a comparing function to have a void return type.
– Carcigenicate
Nov 10 at 19:04
@Carcigenicate I had a void return type in my function declaration.. Thanks for pointing me in the right direction
– whelanevan6
Nov 10 at 19:06
1
Strange you would discover the error now, since the error message you posted is stating exactly what @Carcigenicate pointed out.
– PaulMcKenzie
Nov 10 at 19:09
@PaulMcKenzie I misinterpreted the error and didn't even remember writing the declaration
– whelanevan6
Nov 10 at 19:11
@whelanevan6 -- often the deluge of error messages and notes that you get when you mess up a template contains exactly the information you need to find the problem. You have to wade through it, but for this example, I'm guessing that somewhere shortly after the error message itself there were a couple of notes that showed where this function was defined and where the conflicting one was declared. Everything from the first "error" message to the next "error" message is discussion about what the first error message means.
– Pete Becker
Nov 10 at 19:23
|
show 2 more comments
4
You seem to have another method elsewhere with the signaturevoid compareByName(const Student &,const Student &), which only differs from the other version by its return type, which isn't allowed. Do you need the other version? It seems odd for a comparing function to have a void return type.
– Carcigenicate
Nov 10 at 19:04
@Carcigenicate I had a void return type in my function declaration.. Thanks for pointing me in the right direction
– whelanevan6
Nov 10 at 19:06
1
Strange you would discover the error now, since the error message you posted is stating exactly what @Carcigenicate pointed out.
– PaulMcKenzie
Nov 10 at 19:09
@PaulMcKenzie I misinterpreted the error and didn't even remember writing the declaration
– whelanevan6
Nov 10 at 19:11
@whelanevan6 -- often the deluge of error messages and notes that you get when you mess up a template contains exactly the information you need to find the problem. You have to wade through it, but for this example, I'm guessing that somewhere shortly after the error message itself there were a couple of notes that showed where this function was defined and where the conflicting one was declared. Everything from the first "error" message to the next "error" message is discussion about what the first error message means.
– Pete Becker
Nov 10 at 19:23
4
4
You seem to have another method elsewhere with the signature
void compareByName(const Student &,const Student &), which only differs from the other version by its return type, which isn't allowed. Do you need the other version? It seems odd for a comparing function to have a void return type.– Carcigenicate
Nov 10 at 19:04
You seem to have another method elsewhere with the signature
void compareByName(const Student &,const Student &), which only differs from the other version by its return type, which isn't allowed. Do you need the other version? It seems odd for a comparing function to have a void return type.– Carcigenicate
Nov 10 at 19:04
@Carcigenicate I had a void return type in my function declaration.. Thanks for pointing me in the right direction
– whelanevan6
Nov 10 at 19:06
@Carcigenicate I had a void return type in my function declaration.. Thanks for pointing me in the right direction
– whelanevan6
Nov 10 at 19:06
1
1
Strange you would discover the error now, since the error message you posted is stating exactly what @Carcigenicate pointed out.
– PaulMcKenzie
Nov 10 at 19:09
Strange you would discover the error now, since the error message you posted is stating exactly what @Carcigenicate pointed out.
– PaulMcKenzie
Nov 10 at 19:09
@PaulMcKenzie I misinterpreted the error and didn't even remember writing the declaration
– whelanevan6
Nov 10 at 19:11
@PaulMcKenzie I misinterpreted the error and didn't even remember writing the declaration
– whelanevan6
Nov 10 at 19:11
@whelanevan6 -- often the deluge of error messages and notes that you get when you mess up a template contains exactly the information you need to find the problem. You have to wade through it, but for this example, I'm guessing that somewhere shortly after the error message itself there were a couple of notes that showed where this function was defined and where the conflicting one was declared. Everything from the first "error" message to the next "error" message is discussion about what the first error message means.
– Pete Becker
Nov 10 at 19:23
@whelanevan6 -- often the deluge of error messages and notes that you get when you mess up a template contains exactly the information you need to find the problem. You have to wade through it, but for this example, I'm guessing that somewhere shortly after the error message itself there were a couple of notes that showed where this function was defined and where the conflicting one was declared. Everything from the first "error" message to the next "error" message is discussion about what the first error message means.
– Pete Becker
Nov 10 at 19:23
|
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
4
You seem to have another method elsewhere with the signature
void compareByName(const Student &,const Student &), which only differs from the other version by its return type, which isn't allowed. Do you need the other version? It seems odd for a comparing function to have a void return type.– Carcigenicate
Nov 10 at 19:04
@Carcigenicate I had a void return type in my function declaration.. Thanks for pointing me in the right direction
– whelanevan6
Nov 10 at 19:06
1
Strange you would discover the error now, since the error message you posted is stating exactly what @Carcigenicate pointed out.
– PaulMcKenzie
Nov 10 at 19:09
@PaulMcKenzie I misinterpreted the error and didn't even remember writing the declaration
– whelanevan6
Nov 10 at 19:11
@whelanevan6 -- often the deluge of error messages and notes that you get when you mess up a template contains exactly the information you need to find the problem. You have to wade through it, but for this example, I'm guessing that somewhere shortly after the error message itself there were a couple of notes that showed where this function was defined and where the conflicting one was declared. Everything from the first "error" message to the next "error" message is discussion about what the first error message means.
– Pete Becker
Nov 10 at 19:23