Re: Operator [] Overloading
Quote:
Originally Posted by souza.vss
can I overload some kind of operator[][] ?
No.
Quote:
Originally Posted by souza.vss
An solution could be an friend operator[] function that retuns another class, like the matrix_line, and then overloading [] again, this time returning the element, right? But i find this solution deselegant and unclear. Any ideas?
If you don't want to overload operator[] to return a proxy object for which operator[] is overloaded then overload operator() to accept two arguments.
Re: Operator [] Overloading
If you make operator[] return a pointer, than the second [] will work as it always does on pointers. However, this gives up the possibility of bounds-checking the second access.
Also, you should note that several well-respected libraries already provide a mathematical matrix class. For instance, Boost.uBLAS and Eigen.
Re: Operator [] Overloading
Quote:
Originally Posted by
souza.vss
matrix A(3,3);
cout << A[0][1];
I think it would be better to use a template class, and aim for syntax like:
matrix<3,3> a;
cout << a(0,1);
Re: Operator [] Overloading
template <typename T>
class Row
{
public:
const T& operator []( int i);
//..........
};
template <typename T>
class <Martix>
{
public:
const Row<T>& operator []( int i);
//..........
};