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

Threaded View

  1. #4
    Join Date
    Jun 2009
    Location
    oklahoma
    Posts
    199

    Re: Array of pointers issue

    Code:
    void board:place(piece p, int x, int y, int z) {
    table[x][y][z] = &p;
    }
    So you are passing in a local copy of piece... then storing the memory address of a local variable.
    THIS IS A BIG NO! As soon as the place() function ends, &p is no longer valid.

    It should be instead something like,
    Code:
    homeBoard->place(this,c);
    .......
    void board:place(piece *p, int x, int y, int z) {
    table[x][y][z] = p;
    }
    Go ahead and pass in the original object, not make a copy of it. The original object was created in main(), so it will still be valid through out the end of the program.
    Last edited by jnmacd; October 22nd, 2010 at 10:45 AM.

Tags for this Thread

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