In the main function below I am trying to pass two array parameters to a friend function which will return the month object back to the main function with the monthly updated weatherreport details. I am studying and this is my first year doing any sort of coding so please just be constructive :?:

class weatherReport
    weatherReport();//default constructor
    ~weatherReport();//destructor Returns all the dynamic memory used by the
    //object to free store
    friend istream& operator>> (istream& fin, weatherReport dailyP[]);
    friend ostream& operator<< (ostream& fout, weatherReport monthlyP);
    int get_dayOfMonth() const;
    int get_highTemp() const;
    int get_lowTemp() const;
    int get_amountRain() const;
    int get_amountSnow() const;
    void set_dayOfMonth(int day);
    void set_highTemp(int hTemp);
    void set_lowTemp(int lTemp);
    void set_amountRain(int rain);
    void set_amountSnow(int snow);
    friend weatherReport monthEnd(weatherReport daily[], weatherReport monthly);
    int dayOfMonth;
    int highTemp;
    int lowTemp;
    int amountRain;
    int amountSnow;

int main()
    weatherReport daily[30], monthly;
    int i;
    ifstream in_stream;

    if (in_stream.fail())
        cout << "Input data file failed to open" << endl;
        return 0;

    in_stream >> daily;

    for (int i = 0; i<MAX_SIZE-1; i++)
        monthEnd(&daily[i], monthly);
        return 0;

Edited by Dani: Formatting fixed

8 Years
Discussion Span
Last Post by edman

Please use [[B][/B]code[B][/B]] tags.

You've declared the monthEnd() function as existing, but you don't appear to have defined it anywhere. If you prototype a function somewhere, there should be a corresponding function elsewhere.

When you compile, make sure to turn as many warning messages on as you can. The compiler should complain about missing functions.

Hope this helps.


Thank you for the response. Yes the function was defined elswhere I just didn't copy the details in my post. I have solved the issue in the meantime. I needed to pass one element of the Daily array with the monthly array at a time, so the [] were not required in the call or the definition.

The compiler I am using is Dev C++ v and prescribed by the university.

Thanks again


Edman did you ever solve your problem as I am experiencing the same problem and would like to know how to solve it?


I didn't solve the problem of passing the whole array to the friend function. I had to pass one element of the array together with a second parameter which was a summary object. In the friend function you then had to do comparisons etc. and pass back the updated summary object. Through all my questions and readings it seams like you have to make use of pointer variables or copy constructors. I am still at entry level, but if you post your code or problem statement I will be more than willing to take a look at it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.