vtable with virtual base class?
I've done some searching and haven't been able to an answer to this
question, but is a vtable (or any other sort of overhead) created/
added with using virtual inheritance to resolve the "diamond problem"
when there are no virtual functions?
For example, let's say that I have a setup like this
class base_data
{
static const int NUM_VALUES = 5;
....
protected:
int m_data[NUM_VALUES];
};
class data_reader : public virtual base_data
{
....
public:
data_reader &operator>>(int &value)
{
value = data[m_index];
m_index = (m_index + 1) % NUM_VALUES;
return *this;
}
....
protected:
int m_index;
};
class data_writer : public virtual base_data
{
....
public:
data_writer &operator<<(int value);
{
data[m_index] = value;
m_index = (m_index + 1) % NUM_VALUES;
return *this;
}
....
protected:
int m_index;
}
class data_reader_and_writer : public data_reader, public data_writer
{
....
};
I realize that the virtual inheritance used with data_reader/
data_writer allows data_reader_and_writer to have only a single
instance of the base_data class that is shared so the reading and
writing will happen from the same array (I realize that the read and
write indexes will be disjoint/independent in this implementation),
but is there anything else that's different about data_reader,
data_writer, or data_reader_and_writer (other than the single instance
of base_data, of course)? Anything else added to them? Or any sort of
performance penalty?
Thanks,
Dave