I'm a beginner in c++ and I've tried so hard to get this working, but i couldn't ... It's a 2 part "home assignment". First I had to do the Interval and a ColorInterval(doesn't matter now) class. And now I've to do this IntervalSet class. I'm not so good with pointers and operator overloading yet and I've rly tried for hours to make this...
So i have an Integer class. Here is all the importent code from it.
class Interval {
protected:
double start;
double end;
public:
Interval(double start, double end) : start(start), end(end) {}
Interval(Interval& copy)
{
this->start = copy.start;
this->end = copy.end;
}
~Interval() {}
virtual void Print()
{
cout << "[ " << start << ", " << end << " ]" << endl;
}
};
What I've to make:
- an IntervalSet class which can store Interval objects
constructor: a number -> it has to dynamic allocate this many pointers to Interval objects
class IntervalSet : public Interval { private: int size; Interval** store; public: IntervalSet( int size ) : size(size) { this->store = new Interval*[this->size]; } ~IntervalSet() { delete[] store; }
And here comes the annoying part, 3 operator overloading.
operator+=
- it gets a pointer to Interval object as parameter and puts the copy of it into the array
operator--
- it removes the previously added element from the array + memory handling
operator<<
- printing the stored Intervals with the Print function from class Interval
I haven't even tried the operator--, just the += and the ostream. And I can't insert them, because I've tried many different way and can't decide which one to insert... :D That's it, hopefully someone can help me and I won't fail my class. :D