Results 1 to 4 of 4

Thread: Question About Arrays inside functions

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Question About Arrays inside functions

    You're passing your matrices by value. This results in a copy being made when the function is entered; all operations take place on those copies, not on the original matrices.

    You need to pass them by reference

    Qt Code:
    1. QVector<QVector<int> >& matrix, QVector<QVector<int> >& result
    To copy to clipboard, switch view to plain text mode 

    (Note the ampersands.)

    The C-style version works because you are effectively doing the same thing. You're passing in a pointer to the external arrays, not a copy. Pass-by-reference works exactly the same way, while providing some syntactic sugar by eliminating the need to dereference the arguments.

  2. The following user says thank you to SixDegrees for this useful post:

    rdelgado (15th June 2011)

  3. #2
    Join Date
    Jun 2011
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Question About Arrays inside functions

    QVector<QVector<int> >& result

  4. The following user says thank you to deyili for this useful post:

    rdelgado (15th June 2011)

  5. #3
    Join Date
    Nov 2009
    Posts
    29
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Question About Arrays inside functions

    It Worked! Thanks!!!

Similar Threads

  1. Cannot call OpenCV 2.0 functions inside Qt slots
    By Asfer in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2010, 11:48
  2. debugging arrays
    By divide in forum Qt Tools
    Replies: 1
    Last Post: 12th October 2009, 21:17
  3. QtScript and arrays
    By supergillis in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2009, 19:13
  4. Question about functions in classes
    By cwnelatury in forum Newbie
    Replies: 1
    Last Post: 13th May 2009, 06:05
  5. simple question on pointer-arrays
    By mickey in forum General Programming
    Replies: 2
    Last Post: 17th February 2007, 01:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.