How come the output of this program is 1413, I expected it to be 1414.
(i + 1)->value() should have called R::value(). is n't it?
#include<iostream>
#include<vector>
using namespace std;
class Q
{
public:
Q(int n = 0) : m_n(n) { }
virtual int value() const { return m_n; }
virtual ~Q() { }
protected:
int m_n;
};
class R : public Q
{
public:
R(int n = 0) : Q(n) { }
virtual int value() const { return m_n + 1; }
};
int main(void)
{
const Q a(1);
const R b(3);
const Q *x[2] = { &a, &b };
typedef std::vector<Q> V;
V y;
y.push_back(a);
y.push_back(b);
V::const_iterator i = y.begin();
std::cout << x[0]->value() << x[1]->value()
<< i->value() << (i + 1)->value() << std::endl;
}