I am a begginer, i have only been learning for about 5-6 months, but, from what i know, the
void
or
int
or anything else you put behind the name of the function sets the return type, meaning that this:
1 2 3 4
|
int foo(int bar){
bar *= 3;
return bar;
}
|
Is a function that can only return an int variable.
IF, it is void, it means that is is just a
function, not a return function. Therefore,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
void sortbyName(vector<Person>& persons)
{
sort( persons.begin( ), persons.end( ), [ ]( const Person& lhs, const Person& rhs )
{
if(lhs.lastname != rhs.lastname)
{
return strcasecmp(lhs.lastname.c_str(), rhs.lastname.c_str()) < 0; //strcasecmp är samma sak som stricmp i windows
}
else
{
return strcasecmp(lhs.firstname.c_str(), rhs.firstname.c_str()) < 0; //strcasecmp är samma sak som stricmp i windows
}
});
cout << "\nList is now sorted by name \n\n";
}
|
Should technically always return NULL, although, as i said in the beginning, I am practically a n00b