Constructor Question

Hello,

I'm having some trouble with a program I'm writing involving the construction of a class. The class includes a vector whose type is of another class. There are two separate classes, Interval (which holds a low and a high value) and IntervalSet (which holds the vector of Intervals). I'm very lost as to how I have to word the constructor in both the .cpp and header files.

I have this for the constructor in interval.cpp:

1
2
3
Interval::Interval (double l, double h)
  : low(l), high(h)
{}


And this is part of interval.h:

1
2
3
4
5
6
7
8
class Interval {
private:
  double low;
  double high;

public:
  // Construct a new interval with the indicated bounds
  Interval (double l, double h);


This is the beginning of IntervalSet.h:
1
2
3
class IntervalSet {
private:
  std::vector<Interval> seq; 


If anyone could give me a good hint or two as how to make the constructor, I will be sure to figure it out :)
Last edited on
- Since you're using private members, you should also define your setters and getters for 'Interval'

- //Construct a new interval with the indicated bounds -if this is your directive then it probably means that your constructor needs a default value for low and high :?

- as for 'IntervalSet', I'm sorry I can't comment more -if you only need a vector of Intervals then std::vector<Interval> intervalList(10); is probably enough

-
I'm very lost as to how I have to word the constructor in both the .cpp and header files.

you can see some basic examples here: http://www.cplusplus.com/doc/tutorial/classes/ and here: http://www.cplusplus.com/doc/tutorial/classes2/
Topic archived. No new replies allowed.