From: Gunter Winkler (guwi17_at_[hidden])
Date: 2007-09-19 17:43:17
Am Mittwoch, 19. September 2007 17:44 schrieb Mei, Longyu:
> Do we have a method like "at(i)" in vector to retrieve a specific
> element from a matrix? I know we can use "myMatrix(i, j)" to get an
> value from matrix but if I only have a pointer to a matrix, I cannot
> do "myMatrixPtr->(i, j)" and "myMatrixPtr(i, j)". Is there a function
> can be used in a matrix pointer to retrieve an element?
> "(*myMatrixPtr)(i, j)" looks ugly to me to get a value from a matrix
you can also use
which is not much better, though.
Of course you can always use the sparse interface (without any penalty)
for dense matrices:
However this returns a (writable) reference and is not applicable on
const types. For dense matrices there is no difference between a (read
only) const_reference and a (writable) reference. For triangular,
banded and sparse matrices the writable reference may be slow and have
unwanted side effects if used carelessly.
PS: (*myMatrixPtr)(i,j) is not ugly - it clearly expresses what
operator->() hides: first dereference, then invoke method. (and with
only one additional character!)