Thread: question about sorting function arguments

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by rcgldr
    The parameter could be a reference to a row in a matrix, although it would need a cast to be used this way.
    That doesn't make much sense to me though: if you want to set a particular entry in a given row, and you have a reference to a row in the matrix as the parameter, shouldn't the function just set the entry according to the column, and then the caller just pass the required row? A cast seems completely unnecessary, and if it were necessary, then perhaps this approach is a poor approach because it leads to a double complication. Consider:
    Code:
    #define NROW 2
    #define NCOL 3
    
    void foo(int (&x)[NCOL])
    {
        x[2] = 1;
    }
    
    int main()
    {
        static int m[NROW][NCOL];
        foo(m[1]);
        return 0;
    }
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Quote Originally Posted by rcgldr View Post
    The parameter could be a reference to a row in a matrix, although it would need a cast to be used this way.
    Quote Originally Posted by laserlight View Post
    That doesn't make much sense to me though: if you want to set a particular entry in a given row, and you have a reference to a row in the matrix as the parameter, shouldn't the function just set the entry according to the column, and then the caller just pass the required row?
    Yes, but I was trying to show how other rows of the matrix could be accessed within the called function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-21-2008, 04:27 PM
  2. Yet another function arguments question
    By audinue in forum C Programming
    Replies: 3
    Last Post: 10-20-2008, 05:09 AM
  3. Replies: 9
    Last Post: 01-02-2007, 04:22 PM
  4. Easy question about arguments in a function
    By pond-person in forum C++ Programming
    Replies: 5
    Last Post: 12-12-2002, 10:36 PM
  5. Replies: 2
    Last Post: 03-07-2002, 10:14 AM

Tags for this Thread