CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Dec 2009
    Posts
    11

    simple constructor question

    I'm writing a simple game application. A game object is composed of a Board and an AI player. When the AI player is constructed it needs a reference to a board object, so it can interact with it. How can I set up the game class so that its members get constructed properly--considering that one needs a reference to another?

    Code:
    class Game
    {
        private:
            Board theBoard;
            AI computerPlayer;  // AI needs reference to theBoard (above)
    };
    
    class AI
    {
        AI(Board& board_in) : theBoard(board_in)
    
        private:
            Board& theBoard;
    };
    Last edited by mjl3434; June 28th, 2010 at 02:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured