Results 1 to 4 of 4

Thread: Question About Arrays inside functions

Threaded View

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

    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)

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, 12:48
  2. debugging arrays
    By divide in forum Qt Tools
    Replies: 1
    Last Post: 12th October 2009, 22:17
  3. QtScript and arrays
    By supergillis in forum Qt Programming
    Replies: 1
    Last Post: 20th May 2009, 20:13
  4. Question about functions in classes
    By cwnelatury in forum Newbie
    Replies: 1
    Last Post: 13th May 2009, 07:05
  5. simple question on pointer-arrays
    By mickey in forum General Programming
    Replies: 2
    Last Post: 17th February 2007, 02: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.