The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

corwin17's c++ corner: 03/27 operator overloading by corwin172014-03-27 10:45:15
  operator overloading by lenmear2014-03-27 11:05:43
    I think I understand, but by corwin172014-03-27 11:49:10
      Use the accessors by lenmear 2014-03-27 12:00:32
// using an external function, you'll need to create a new
// matrix object to return.  you don't want to return a
// reference to it.
//matrix& operator+ (const matrix& A, const matrix& B)
matrix operator+ (const matrix& A, const matrix& B)
{
  // you need to instantiate a matrix object to hold the result:
  matrix C;

  // since this is an external function, use the accessor methods
  //for(int ii=0 ; ii<A.nrow ; ii++)
  for(int ii=0 ; ii<A.getRows() ; ii++)
  {
    // ditto for columns
    for(int jj=0 ; jj<A.ncol ; jj++)
    {
      // here, use setElement and getElement
      //p[ii][jj] = A.p[ii][jj] + B.p[ii][jj];
      double element = A.getElement(ii, jj) +
                       B.getElement(ii, jj);
      C.setElement(ii, jj, element);
    }
  }

  // then, you need to return the result
  return C;
}
</pre>

As to your PS, I use the pre tag.  I think the code tag changes to a monospace font, but doesn't preserve white space.
[ Reply ]
        Danger, Will Robinson! by lenmear2014-03-27 12:27:00
          And people wonder why I refuse to learn OOP. by firehawk2014-03-27 12:38:20
            And why I've refused until thrust upon me! (n/t) by corwin172014-03-27 12:42:35
            OOP isn't that bad, it's the unmanaged langauges by Freakazoid2014-03-27 12:47:50
              I use PHP, and I've seen PHP OOP... by firehawk2014-03-27 12:53:53
          <Deleted><Deleted>2014-03-27 22:45:15
            Whoa! Mods! B-Usted Horizontal Scroll! by wwill2014-03-27 22:25:19
        Thought of that just after submitting, but... by corwin172014-03-27 12:40:52

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)