Mega Code Archive
Store a class object in a vector
#include
#include
using namespace std;
class Demo {
double d;
public:
Demo() {
d = 0.0;
}
Demo(double x) {
d = x;
}
Demo &operator=(double x) {
d = x; return *this;
}
double getd() {
return d;
}
};
bool operator<(Demo a, Demo b)
{
return a.getd() < b.getd();
}
bool operator==(Demo a, Demo b)
{
return a.getd() == b.getd();
}
int main()
{
vector v;
int i;
for(i = 0; i <10; i++)
v.push_back(Demo(i/3.0));
for(i = 0; i