Thread: How do I return an Array?

  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
    39,659
    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.

  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.

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, 09:02 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Another weird error
    By rwmarsh in forum Game Programming
    Replies: 4
    Last Post: 09-24-2006, 10:00 PM
  4. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM
  5. opengl help
    By heat511 in forum Game Programming
    Replies: 4
    Last Post: 04-05-2004, 01:08 AM