CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2006
    Posts
    3

    Talking Simple Vector Problem

    New to C++ and Programming in General. Have a quick question about my code.

    Code:
    //Legal Move Generator
    void legal_move(vector<int> &move, position board[], int size);
    
    //Generate Moves
    void legal_move(vector<int> &move, position board[], int size){
    	int counter = 0;
    	for(counter; counter <= size; counter++){
    		if(board[counter].occupied == 0){
    			//Assign the value of counter to the vector move, and so on
    		}
    	}
    }
    I would just use an array in the function, but obviously the legal moves will grow and shrink, so I thought a vector would be a better fit. The question is in the comment under the if condition--

    Thanks for any help.

  2. #2
    Join Date
    Jun 2002
    Location
    Germany
    Posts
    1,557

    Re: Simple Vector Problem

    tilt,

    Your question is unclear. Please phrase your question in the form of a question.

    Chris.
    You're gonna go blind staring into that box all day.

  3. #3
    Join Date
    Jun 2006
    Posts
    3

    Re: Simple Vector Problem

    Opps, thanks for the help though. Got it.
    Last edited by tilt; June 19th, 2006 at 04:09 PM.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Simple Vector Problem

    Quote Originally Posted by tilt
    Still, I don't know how to assign the square numbers to the vector:
    So learn with a small test program. You should start out with a simple example of how to use a vector instead of putting a live (or developing) application through this learning process. Once you know how to use vector, then and only then should you use it in a larger application.
    Code:
    #include <vector>
    
    void foo(std::vector<int>& v)
    {
       // what do you want to do with v?
    }
    
    int main()
    {
       std::vector<int> MyVect; 
    //...
       foo( MyVect );  
    }
    //...etc
    Now, from this simple program, what exactly is it you want to do? Whatever it is, you can test it very easily, all without bringing up game boards, occupied squares, etc.

    So is MyVect empty? Does it already have data?

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Jun 2006
    Posts
    3

    Re: Simple Vector Problem

    Thanks for the advice Paul, I appreciate that.

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