A
Arne Schmitz
I guess this has been asked before, but I cannot find any answer to this
problem. I have program like this:
---SNIP---
#include <cassert>
#include <cstdlib>
class C
{
public:
inline operator float*() { return v; }
inline float& operator[](size_t i) { assert(i < 3); return v; }
inline const float& operator[](size_t i) const
{ assert(i < 3); return v; }
private:
float v[3];
};
int main()
{
C c;
c[1] = 0.0f;
return 0;
}
---SNIP---
Now, this does not compile, because the float* and the [] clash, since []
uses size_t (or unsigned) and the operator[] implicitly defined by the
float* conversion, also uses size_t, as far as I understand. Is there a way
to define both operators at the same time, while keeping the size_t of
operator[](size_t)?
Arne
problem. I have program like this:
---SNIP---
#include <cassert>
#include <cstdlib>
class C
{
public:
inline operator float*() { return v; }
inline float& operator[](size_t i) { assert(i < 3); return v; }
inline const float& operator[](size_t i) const
{ assert(i < 3); return v; }
private:
float v[3];
};
int main()
{
C c;
c[1] = 0.0f;
return 0;
}
---SNIP---
Now, this does not compile, because the float* and the [] clash, since []
uses size_t (or unsigned) and the operator[] implicitly defined by the
float* conversion, also uses size_t, as far as I understand. Is there a way
to define both operators at the same time, while keeping the size_t of
operator[](size_t)?
Arne