CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2002
    Posts
    37

    Compiler error when using pass by reference

    I have been working on a little project and keep getting this error when I use the code that follows. If anyone knows why this happens (using vc++.net compiler) please let me know. The error goes away when I use pass by value instead, but since I am passing a struct, I want to use pass by reference.

    ERROR:
    error C2664: 'CSquareInfo::RemovePiece' : cannot convert parameter 1 from 'PIECEDATA *__w64 ' to 'PIECEDATA &'


    ///////////////////////////////////////////////////////////////////////////////
    HEADER FILE - function declaration:

    bool RemovePiece(PIECEDATA &pieceData); //PIECEDATA is a struct

    ////////////////////////////////////////////////////////////////////////////////
    IMPLIMENTATION FILE - function

    bool CSquareInfo::RemovePiece(PIECEDATA &pieceData)
    {
    PIECEDATA empty;
    if(pieceData.COLOR == LIGHT && pieceData.ID == vLight[numLight - 1].id)
    {
    vLight[numLight - 1].SetPieceData(empty);
    numLight--;
    numTotal--;
    return true; // successful
    }
    else if(pieceData.COLOR == DARK && pieceData.ID == vDark[numDark - 1].id)
    {
    vDark[numDark - 1].SetPieceData(empty);
    numDark--;
    numTotal--;
    return true; // successful
    }
    else
    {
    return false; // unsuccessful
    }
    }

    ///////////////////////////////////////////////////////////////////////////////
    CALL THAT CAUSES ERROR:

    object.RemovePiece(&pData1);

    note: object is of type CSquareInfo and pData1 is a PIECEDATA struct and is not a pointer (despite the p before Data1).
    "There's a huge trust. I see it all the time when people
    come up to me and say, 'I don't want you to let me down again.'"
    - George W Bush

  2. #2
    Join Date
    Sep 2002
    Location
    Singapore
    Posts
    673
    The call should be as below,

    object.RemovePiece(pData1);

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