overloading operator [] for a matrix
-
Hello, for a vector, overloading the operator [] is easy, you return the data of the position given to the function operator[]. i'm trying to find out how to do it with a matrix. i found the () approach here: http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.8 to sum it up,there you overload the (), and you access the matrix by doing for example mat(3,3)=2; I want an implementation that works with mat[3][3]=2;. i found this http://www.devhood.com/tutorials/tutorial\_details.aspx?tutorial\_id=502 , but i don't understand how it works. i just need an answer of how it works. i need to answer a question, not to make some code work. i'll really appreciate your help. thanks!
-
Hello, for a vector, overloading the operator [] is easy, you return the data of the position given to the function operator[]. i'm trying to find out how to do it with a matrix. i found the () approach here: http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.8 to sum it up,there you overload the (), and you access the matrix by doing for example mat(3,3)=2; I want an implementation that works with mat[3][3]=2;. i found this http://www.devhood.com/tutorials/tutorial\_details.aspx?tutorial\_id=502 , but i don't understand how it works. i just need an answer of how it works. i need to answer a question, not to make some code work. i'll really appreciate your help. thanks!
Matrix::operator[]
returns a different type of C++ object, a row. That's what you get frommat[3]
. Then the row class also overloadsoperator[]
and returns a value from the row. --Mike-- Personal stuff:: Ericahist | Homepage Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ ---- "Linux is good. It can do no wrong. It is open source so must be right. It has penguins. I want to eat your brain." -- Paul Watson, Linux Zombie -
Hello, for a vector, overloading the operator [] is easy, you return the data of the position given to the function operator[]. i'm trying to find out how to do it with a matrix. i found the () approach here: http://www.parashift.com/c++-faq-lite/operator-overloading.html#faq-13.8 to sum it up,there you overload the (), and you access the matrix by doing for example mat(3,3)=2; I want an implementation that works with mat[3][3]=2;. i found this http://www.devhood.com/tutorials/tutorial\_details.aspx?tutorial\_id=502 , but i don't understand how it works. i just need an answer of how it works. i need to answer a question, not to make some code work. i'll really appreciate your help. thanks!
-