I needed some help on reference parameters with my C++ code

  address-operator, c++, reference, reference-parameters

I am learning OOP and don’t know how to use the reference parameters appropriately.
I am trying to return the values of the month day and year from the set function. I was told to use reference parameters to assign them the previous value, but I am confused on what I need to do to return the three values of month, day, and year in the void getDate function:
This is the file that stores the function definitions

#include <iostream>
#include "date.h"
using namespace std;


//create a function that will set the date 
bool Date::setDate(int d, int mon, int yer)
{
    //if day is greater than 30/ less that 1 (BAD DATA)
    if (d > 30 || d < 1)
        return false;
    //if month is greater than 12 or less than 1 (BAD DATA)
    if (mon > 12 || mon < 1)
        return false;
    //store day and month into private variable length
    day = d;
    month = mon;
    return true;

}

void getDate(int&d , int& mon,int& yer)
{
    //this function will use reference parameters
    //we need to return all THREE values together
    //use & operator to pass
    d = 10;
    mon = 11;
    yer = 2000;

    
}

And this is the file that includes main : 
#include <iostream>
#include "date.h"

int main()
{
    //create an object/ BOX
    Date box;
}

Along with the .h file

#pragma once
#include <iostream>
using namespace std;

// This header file holds the class and its functions
class Date
{
private:
    int month, day, year;
public:
    //Date();
   //Date(int, int, int);
    bool setDate(int, int, int);
    void getDate(int&, int&, int&);
    //void printShort();
    //void printLong();
    //bool isEqual(Date);
    //void increment();
   //void decrement();
};

Source: Windows Questions C++

LEAVE A COMMENT