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