Quote:
The console is only returning the y
That is the correct behaviour of the
comma operator (see
here[
^]).
Anyway a
C/C++
function returns a single value.
However, the
single return value could be an object (instance of a class or a struct) and you may define the insertion operator for such a struct or class, e.g.
#include <iostream>
using namespace std;
struct DOB {
int m, d, y;
};
ostream & operator << (ostream & os, const DOB & dob)
{
return os << dob.m << " " << dob.d << " " << dob.y;
}
DOB doDateofBirth(int m , int d , int y);
int main()
{
cout << "My DoB is, " << doDateofBirth(4,14,1998) << endl;
}
DOB doDateofBirth(int m,int d,int y)
{
DOB dob;
dob.m = m; dob.d = d; dob.y = y;
return dob;
}