J
Jaco Naude
Hi
I'm building a 3D matrix and I've overloaded the () operators as
follow:
//! Subscript operator overload.
complex<double> operator() (unsigned x, unsigned y, unsigned z);
//! Subscript operator const overload.
complex<double> operator() (unsigned x, unsigned y, unsigned z) const;
In these functions I return the value at the given position. Reading
the values works fine, but assigning them does not.
For example, the following does not work:
Matrix matrix1(10,10,10);
complex<double> value(2,2);
matrix1(1,1,1) = value;
I followed the following topic in the C++ FAQ: [13.10] How do I create
a subscript operator for a Matrix class?
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.10
At the end of the topic they say that the following should be
possible:
Matrix m(10,10);
m(5,8) = 106.15;
I don't see what they did different than my implementation and I don't
understand why it should be possible with just the two overloaded
operators.
Any insights will be appreciated.
Thanks,
Jaco
I'm building a 3D matrix and I've overloaded the () operators as
follow:
//! Subscript operator overload.
complex<double> operator() (unsigned x, unsigned y, unsigned z);
//! Subscript operator const overload.
complex<double> operator() (unsigned x, unsigned y, unsigned z) const;
In these functions I return the value at the given position. Reading
the values works fine, but assigning them does not.
For example, the following does not work:
Matrix matrix1(10,10,10);
complex<double> value(2,2);
matrix1(1,1,1) = value;
I followed the following topic in the C++ FAQ: [13.10] How do I create
a subscript operator for a Matrix class?
http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.10
At the end of the topic they say that the following should be
possible:
Matrix m(10,10);
m(5,8) = 106.15;
I don't see what they did different than my implementation and I don't
understand why it should be possible with just the two overloaded
operators.
Any insights will be appreciated.
Thanks,
Jaco