This is a compiler error that I get when I try to do:
void* p;
unsigned int stride;
// ...
p += stride;
I have good reason to do this, namely an iterator over an array of
object whose type may vary, as outlined below. So I don't understand why
it is a compiler error and not only a warning. I can superced this by:
p = ((char*) p)+1;
but I don't like it.
class Type;
class TypeA : public Type; // has as sizeof 10 for example
class TypeB : public Type; // has as sizeof 20 for example
class Parent
{
public:
class Iterator
{
public:
Type* operator->() const { return reinterpret_cast<Type*>(p_); }
Iterator& operator++() { p_ += stride_; return *this; }
protected:
friend class Parent;
Iterator(void* p,int s) : p_(p),stride_(s) {}
private:
void* p_;
int stride_;
}
protected:
template <class T>
Iterator iterator(const T* t)
{
return Iterator(t,sizeof(T));
}
};
Then I can have sublclasses of Parent using vectors of TypeA or TypeB on
which I can iterate using the Type interface thru the Parent interface.
--
+-------------------------------------------------+
| Xavier Décoret - Post Doct |
| Graphics Lab (LCS) - MIT |
| mailto: de*****@graphics.lcs.mit.edu |
| home : http://www.graphics.lcs.mit.edu/~decoret|
+-------------------------------------------------+