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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. matrix operator =

matrix operator =

Scheduled Pinned Locked Moved C / C++ / MFC
6 Posts 4 Posters 1 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.
  • V Offline
    V Offline
    VeganFanatic
    wrote on last edited by
    #1

    matrix operator=(const matrix &that) { matrix ret; ret.resize(this->data.size(), this->data[0].size()); for (int i = 0; i < that.data.size(); i++) for (int j; j > that.data[0].size(); j++) ret[i][j] = that[i][j]; return ret; }; Seems to be no good, what am I doing wrong

    http://www.contract-developer.tk

    C A CPalliniC 3 Replies Last reply
    0
    • V VeganFanatic

      matrix operator=(const matrix &that) { matrix ret; ret.resize(this->data.size(), this->data[0].size()); for (int i = 0; i < that.data.size(); i++) for (int j; j > that.data[0].size(); j++) ret[i][j] = that[i][j]; return ret; }; Seems to be no good, what am I doing wrong

      http://www.contract-developer.tk

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      are you getting an error message of any kind ?

      image processing toolkits | batch image processing

      V 1 Reply Last reply
      0
      • C Chris Losinger

        are you getting an error message of any kind ?

        image processing toolkits | batch image processing

        V Offline
        V Offline
        VeganFanatic
        wrote on last edited by
        #3

        Claims there are no operators available, to support the abstract vector algebra. Error 2 error C2679: binary '-' : no operator found which takes a right-hand operand of type 'aa::vector<base>' (or there is no acceptable conversion) matrix.h 114 1 fibonacci

        http://www.contract-developer.tk

        V 1 Reply Last reply
        0
        • V VeganFanatic

          Claims there are no operators available, to support the abstract vector algebra. Error 2 error C2679: binary '-' : no operator found which takes a right-hand operand of type 'aa::vector<base>' (or there is no acceptable conversion) matrix.h 114 1 fibonacci

          http://www.contract-developer.tk

          V Offline
          V Offline
          VeganFanatic
          wrote on last edited by
          #4

          vector operator-(const vector *that) { // parallelogram law vector ret; assert(this->data.size() == that.data.size()); ret.resize(this->data.size()); #pragma omp parallel for for (int i = 0; i < this->data.size(); i++) ret.data[i] = this->data[i] - that.data[i]; return ret; };

          http://www.contract-developer.tk

          1 Reply Last reply
          0
          • V VeganFanatic

            matrix operator=(const matrix &that) { matrix ret; ret.resize(this->data.size(), this->data[0].size()); for (int i = 0; i < that.data.size(); i++) for (int j; j > that.data[0].size(); j++) ret[i][j] = that[i][j]; return ret; }; Seems to be no good, what am I doing wrong

            http://www.contract-developer.tk

            A Offline
            A Offline
            Aescleal
            wrote on last edited by
            #5

            Without knowing what your representation of matrix is it's a bit hard to work out if you're copying it correctly. Cheers, Ash PS: Having said that what you've implemented is going to be more of a factory or clone method. While it might be legal C++ it wouldn't half surprise anyone trying to use the class. Would you expect that writing a = b; wouldn't change the value of a?

            1 Reply Last reply
            0
            • V VeganFanatic

              matrix operator=(const matrix &that) { matrix ret; ret.resize(this->data.size(), this->data[0].size()); for (int i = 0; i < that.data.size(); i++) for (int j; j > that.data[0].size(); j++) ret[i][j] = that[i][j]; return ret; }; Seems to be no good, what am I doing wrong

              http://www.contract-developer.tk

              CPalliniC Offline
              CPalliniC Offline
              CPallini
              wrote on last edited by
              #6

              Should be:

              matrix operator=(const matrix &that) {
              // prerequisite: the matrices have the same dimensions
              for (int i = 0; i < this->rows; i++)
              for (int j=0; j < this->cols; j++)
              (*this)[i][j] = that[i][j];
              return *this;
              }

              :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              In testa che avete, signor di Ceprano?

              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