Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. overloading operator [] for a matrix

overloading operator [] for a matrix

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionc++htmlcom
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kfaday
    wrote on last edited by
    #1

    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!

    M R 2 Replies Last reply
    0
    • K kfaday

      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!

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      Matrix::operator[] returns a different type of C++ object, a row. That's what you get from mat[3]. Then the row class also overloads operator[] 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

      1 Reply Last reply
      0
      • K kfaday

        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!

        R Offline
        R Offline
        Roger Allen
        wrote on last edited by
        #3

        This article[^] which is a matrix calss overrides operator[] and a pseudo operator[][] take a look. If you vote me down, my score will only get lower

        K 1 Reply Last reply
        0
        • R Roger Allen

          This article[^] which is a matrix calss overrides operator[] and a pseudo operator[][] take a look. If you vote me down, my score will only get lower

          K Offline
          K Offline
          kfaday
          wrote on last edited by
          #4

          thanks roger, nice article

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups