How do I return an Array?

This is a discussion on How do I return an Array? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Cat In general, whenever you USE the array (e.g. when you want to print it out, or ...

  1. #16
    Registered User
    Join Date
    Oct 2006
    Posts
    13
    Quote Originally Posted by Cat
    In general, whenever you USE the array (e.g. when you want to print it out, or use the board to draw the screen, etc.) you're going to need to loop element by element through the array anyway, regardless of whether your function returns the whole array or not.

    When you have something like a game board, looping through each element is unavoidable.

    Ok. In this case I have a few different which perform operations on the array and as is each one has to get it bit by bit.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    What kind of board are you trying to implement?

    Something like chess would be perhaps
    Code:
    enum Piece { none, pawn, rook, /* and so on */ };
    class Board
    {
    public:
            Board(void);
            // rank is 1 to 8, file is 'a' to 'h' as per normal chess rules
            void setPiece( Piece piece, int rank, char file );
            Piece getPiece ( int rank, char file );
    private:
            Piece board[8][8];
    };
    Start from the top and think about the overall aims of the class and the kind of higher level operations you'll need.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    13
    Quote Originally Posted by Salem
    What kind of board are you trying to implement?


    Start from the top and think about the overall aims of the class and the kind of higher level operations you'll need.
    It was a 15 puzzle board like here. Got it sorted now. Tnx.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. is it ok like that?
    By ExDHaos in forum C++ Programming
    Replies: 8
    Last Post: 05-23-2009, 10:02 AM
  2. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  3. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 11:00 PM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 11:50 AM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 02:08 AM

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