Mega Code Archive
Store a class object in a vector
#include
#include
#include
using namespace std;
class DailyTemp {
int temp;
public:
DailyTemp() { temp = 0; }
DailyTemp(int x) { temp = x; }
DailyTemp &operator=(int x) {
temp = x; return *this;
}
double get_temp() { return temp; }
};
bool operator<(DailyTemp a, DailyTemp b)
{
return a.get_temp() < b.get_temp();
}
bool operator==(DailyTemp a, DailyTemp b)
{
return a.get_temp() == b.get_temp();
}
int main()
{
vector v;
unsigned int i;
for(i=0; i<7; i++)
v.push_back(DailyTemp(60 + rand()%30));
cout << "Fahrenheit temperatures:\n";
for(i=0; i