How to use an object from another class

I have two classes one called Date and the other is University , Date class has two overloaded operators , ostream and istream to take in the data and print them out :

ostream & operator<<(ostream & out, Date & x)
{
out<< x.month << "/" << x.day << "/" << x.year ;
return out;
}
istream & operator>>(istream & in, Date & x)
{
in>> x.day >> x.month >> x.year ;
return in;
}


The University class has an object of type Date called establishDate and I must use this to print out the date along with the University name and location, here's University class :

University.h

class University {
public:
University (); // constructor
friend ostream & operator<<(ostream & out, University & x); // print the university data
friend istream & operator>>(istream & in, University & x); // to read university data
private:
const static string uname;
string location;
Date establishDate;
};

const string uname = "London University";


so how do I use the establishDate object ?
in exactly the same way as if it wasn't in a class.

pseudo:

1
2
3
4
5
University myUniObject;

std::cout << "Date established: " << myuniObject.establishDate;

Last edited on
Hi,

Please follow below link for C language tutorial and interview questions

http://www.gcreddy.com/2012/01/c.html
Topic archived. No new replies allowed.