Hi everybody,
I'm having trouble getting the right size of a vector with struct elements. The element class is defined like this (I didn't omit any detail even though I think the only relevant fact is that it is a class containing an int and two doubles):
class Interval
{
public:
Interval(int _i = 0, scalar _l = 0, scalar _r = 0) :
index(_i),
l(_l),
r(_r)
{ }
inline double left(void) const { return l; }
inline double right(void) const { return r; }
inline bool operator < (const Interval & i2) const { return left() < i2.left(); }
public:
int index;
double l;
double r;
};
Then in a function I have this code:
std::vector<Interval> arr(10);
int s1 = arr.size();
int s2 = arr.end() - arr.begin();
The value of s1 I get is 15, while s2 is the correct value 10. What is going on? Isn't size() supposed to return exactly the number of elements? Isn't it supposed to be the same as arr.end() - arr.begin()?
Any response and comment is appreciated.