Arrays as function parameters

This is a discussion on Arrays as function parameters within the C++ Programming forums, part of the General Programming Boards category; Hi, I'm new to this forum and fairly new to C++ programming. I was working on a program today when ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Arrays as function parameters

    Hi,
    I'm new to this forum and fairly new to C++ programming. I was working on a program today when I got stuck on something and I'm wondering if someone could help me out.
    Ok, so I'm wondering if it's possible to use a array name as a parameter in a function that I can plug different arrays in (with the same dimensions). These are the basics of how my program went (with unimportant stuff left out):


    void check_flags(int moves[], int flags[], int win_lose);

    int main()
    {
    int winflags[3][7];
    int loseflags[3][7];
    int moves[7];
    int win_lose = 1;
    check_flags(moves, winflags, win_lose);
    int win_lose = 2;
    check_flags(moves, loseflags, win_lose);
    }

    void check_flags(int moves[], int flags[], int win_lose)
    {
    //do some stuff here using flags[] (but have it stand for either winflags[] or loseflags[])
    }


    I hope this explains my problem well enough... In this situation I want to substitute the 2 different arrays (winflags and loseflags) into parameter 2 of the function. I guess I could write two different functions, one for each, but I was wondering if there was a way this could be done.
    Thanks

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    void check_flags(int moves[], int flags[], int win_lose);
    should be
    void check_flags(int moves[], int flags[][7], int win_lose);
    kooma - t.h@iki.fi

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    2
    Thanks alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 06:45 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 10:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21