Problem with Calling Methods from Objects which are stored in an array from within another Object

Discussion in 'C++' started by Andreas Schmitt, Jul 28, 2005.

  1. Ok. I got the following problem. I created the following array and executed
    a function :

    CField* Spielfeld[20][20];

    CreatePlayField( Spielfeld );

    *************************************************
    ******** CreatePlayField looks like this ************
    *************************************************

    // Set PlayField Coordinates and Size
    void CreatePlayField( CField* PlayField[20][20] )
    {
    for ( int tmpx = 1; tmpx<=20; tmpx++ )
    {
    for ( int tmpy = 1; tmpy<=20; tmpy++ )
    {
    PlayField[tmpx][tmpy] = new CField;

    PlayField[tmpx][tmpy]->SetXCoord( (tmpx-1)*FLD_WIDTH +
    (tmpx*2) );
    PlayField[tmpx][tmpy]->SetYCoord( (tmpy-1)*FLD_HEIGHT +
    (tmpy*2) );
    PlayField[tmpx][tmpy]->SetWidth( FLD_WIDTH );
    PlayField[tmpx][tmpy]->SetHeight( FLD_HEIGHT );
    }
    }
    }

    **************************************
    ** Till here all this works
    **************************************

    **********************************************************************************************
    **** Later in the code a function of the CDirect3D-Object 'Direct3D' is
    called like this
    **********************************************************************************************

    Direct3D.Init(hWnd, Spielfeld);

    ***********************************
    **** ...and the problematic part looks like this
    ***********************************

    BOOL CDirect3D::Init(HWND hWnd, CField* PlayField[20][20], BOOL bWindowed)
    {
    ....


    for ( int x = 1; x<=20; x++ )
    {
    for ( int y = 1; y<=20; y++)
    {
    m_RFieldRect[x][y] = (PlayField[x][y]->GetXCoord,
    PlayField[x][y]->GetYCoord,
    PlayField[x][y]->GetWidth,
    PlayField[x][y]->GetHeight );

    m_lpD3DDevice->ColorFill(m_lpD3DSurface,
    &m_RFieldRect[x][y],
    PlayField[x][y]->GetColor());
    }
    }


    ....

    }

    ******************************************************************************************
    ** Here I get several error messages which say:
    **
    ** g:\Eigene Dateien\Visual Studio Projects\2DSpielfeld\Direct3D.cpp(80):
    error C2475: 'CField::GetXCoord':
    ** forming a pointer-to-member requires explicit use of the address-of
    operator ('&') and a qualified name
    **
    ** The MSDN Help on that error message didn't really help me and I don't
    really know what's the problem
    ** Searching the internet also didn't really help.
    ** My experience with C++ is probably simply not high enough yet to get
    what's the problem here
    ** Any help would be appreciated
    *******************************************************************************************
     
    Andreas Schmitt, Jul 28, 2005
    #1
    1. Advertisements

  2. "Andreas Schmitt" <> schrieb im Newsbeitrag
    news:dc9t5t$r9k$01$-online.com...
    > Ok. I got the following problem. I created the following array and

    executed
    > a function :
    >
    > CField* Spielfeld[20][20];
    >
    > CreatePlayField( Spielfeld );
    >
    > *************************************************
    > ******** CreatePlayField looks like this ************
    > *************************************************
    >
    > // Set PlayField Coordinates and Size
    > void CreatePlayField( CField* PlayField[20][20] )
    > {
    > for ( int tmpx = 1; tmpx<=20; tmpx++ )
    > {
    > for ( int tmpy = 1; tmpy<=20; tmpy++ )
    > {
    > PlayField[tmpx][tmpy] = new CField;
    >
    > PlayField[tmpx][tmpy]->SetXCoord( (tmpx-1)*FLD_WIDTH +
    > (tmpx*2) );
    > PlayField[tmpx][tmpy]->SetYCoord( (tmpy-1)*FLD_HEIGHT +
    > (tmpy*2) );
    > PlayField[tmpx][tmpy]->SetWidth( FLD_WIDTH );
    > PlayField[tmpx][tmpy]->SetHeight( FLD_HEIGHT );
    > }
    > }
    > }
    >
    > **************************************
    > ** Till here all this works
    > **************************************
    >
    >

    ****************************************************************************
    ******************
    > **** Later in the code a function of the CDirect3D-Object 'Direct3D' is
    > called like this
    >

    ****************************************************************************
    ******************
    >
    > Direct3D.Init(hWnd, Spielfeld);
    >
    > ***********************************
    > **** ...and the problematic part looks like this
    > ***********************************
    >
    > BOOL CDirect3D::Init(HWND hWnd, CField* PlayField[20][20], BOOL bWindowed)
    > {
    > ...
    >
    >
    > for ( int x = 1; x<=20; x++ )
    > {
    > for ( int y = 1; y<=20; y++)
    > {
    > m_RFieldRect[x][y] = (PlayField[x][y]->GetXCoord,
    > PlayField[x][y]->GetYCoord,
    > PlayField[x][y]->GetWidth,
    >

    PlayField[x][y]->GetHeight );
    >
    > m_lpD3DDevice->ColorFill(m_lpD3DSurface,
    > &m_RFieldRect[x][y],
    >

    PlayField[x][y]->GetColor());
    > }
    > }
    >
    >
    > ...
    >
    > }
    >
    >

    ****************************************************************************
    **************
    > ** Here I get several error messages which say:
    > **
    > ** g:\Eigene Dateien\Visual Studio Projects\2DSpielfeld\Direct3D.cpp(80):
    > error C2475: 'CField::GetXCoord':



    Try 'CField::GetXCoord()' instead of 'CField::GetXCoord'. That's what I can
    see so far. If this does not solve the problem, paste the code of the class
    CField.


    > ** forming a pointer-to-member requires explicit use of the address-of
    > operator ('&') and a qualified name
    > **
    > ** The MSDN Help on that error message didn't really help me and I don't
    > really know what's the problem
    > ** Searching the internet also didn't really help.
    > ** My experience with C++ is probably simply not high enough yet to get
    > what's the problem here
    > ** Any help would be appreciated
    >

    ****************************************************************************
    ***************
    >
    >
     
    Christian Meier, Jul 28, 2005
    #2
    1. Advertisements

  3. Andreas Schmitt

    Ian Guest

    Re: Problem with Calling Methods from Objects which are stored inan array from within another Object

    Andreas Schmitt wrote:
    > for ( int x = 1; x<=20; x++ )
    > {
    > for ( int y = 1; y<=20; y++)
    > {
    > m_RFieldRect[x][y] = (PlayField[x][y]->GetXCoord,


    I assume GetXCoord is a function, so you are missing the ().

    The compiler is attempting to take the address of GetXCoord.

    Ian
     
    Ian, Jul 28, 2005
    #3
  4. "Ian" <> schrieb im Newsbeitrag
    news:...
    > Andreas Schmitt wrote:
    >> for ( int x = 1; x<=20; x++ )
    >> {
    >> for ( int y = 1; y<=20; y++)
    >> {
    >> m_RFieldRect[x][y] = (PlayField[x][y]->GetXCoord,

    >
    > I assume GetXCoord is a function, so you are missing the ().
    >
    > The compiler is attempting to take the address of GetXCoord.
    >
    > Ian


    Duh! I knew it.. it had to be something this simple.. *g*
    I guess coding all night long makes you become this blind to seeing stuff
    like this

    Thanks to both of you for the quick help anyway
     
    Andreas Schmitt, Jul 28, 2005
    #4
  5. Andreas Schmitt

    Ian Guest

    Re: Problem with Calling Methods from Objects which are stored inan array from within another Object

    Andreas Schmitt wrote:
    > "Ian" <> schrieb im Newsbeitrag
    > news:...
    >
    >>Andreas Schmitt wrote:
    >>
    >>> for ( int x = 1; x<=20; x++ )
    >>> {
    >>> for ( int y = 1; y<=20; y++)
    >>> {
    >>> m_RFieldRect[x][y] = (PlayField[x][y]->GetXCoord,

    >>
    >>I assume GetXCoord is a function, so you are missing the ().
    >>
    >>The compiler is attempting to take the address of GetXCoord.
    >>
    >>Ian

    >
    >
    > Duh! I knew it.. it had to be something this simple.. *g*
    > I guess coding all night long makes you become this blind to seeing stuff
    > like this
    >

    Just think how many hidden bugs the all night session has introduced :)

    Ian
     
    Ian, Jul 28, 2005
    #5
  6. Andreas Schmitt

    Howard Guest

    "Andreas Schmitt" <> wrote in message
    news:dca18m$1fh$02$-online.com...
    >
    > "Ian" <> schrieb im Newsbeitrag
    > news:...
    >> Andreas Schmitt wrote:
    >>> for ( int x = 1; x<=20; x++ )
    >>> {
    >>> for ( int y = 1; y<=20; y++)
    >>> {
    >>> m_RFieldRect[x][y] = (PlayField[x][y]->GetXCoord,

    >>
    >> I assume GetXCoord is a function, so you are missing the ().
    >>
    >> The compiler is attempting to take the address of GetXCoord.
    >>
    >> Ian

    >
    > Duh! I knew it.. it had to be something this simple.. *g*
    > I guess coding all night long makes you become this blind to seeing stuff
    > like this
    >
    > Thanks to both of you for the quick help anyway


    Now that you've got it compiling, you might want to stop it from crashing,
    also. :)

    You're using indexes from 1 through 20. In C++, arrays are indexed starting
    at 0, not 1. Your loops need to start at 0 and only continue while the
    index is _less_than_ 20.

    -Howard



    >
     
    Howard, Jul 28, 2005
    #6
  7. Eeeek!
    You're right of course. Thanks
    Will do

    "Howard" <> schrieb im Newsbeitrag
    news:nQ6Ge.502091$...
    >
    > "Andreas Schmitt" <> wrote in message
    > news:dca18m$1fh$02$-online.com...
    >>
    >> "Ian" <> schrieb im Newsbeitrag
    >> news:...
    >>> Andreas Schmitt wrote:
    >>>> for ( int x = 1; x<=20; x++ )
    >>>> {
    >>>> for ( int y = 1; y<=20; y++)
    >>>> {
    >>>> m_RFieldRect[x][y] = (PlayField[x][y]->GetXCoord,
    >>>
    >>> I assume GetXCoord is a function, so you are missing the ().
    >>>
    >>> The compiler is attempting to take the address of GetXCoord.
    >>>
    >>> Ian

    >>
    >> Duh! I knew it.. it had to be something this simple.. *g*
    >> I guess coding all night long makes you become this blind to seeing stuff
    >> like this
    >>
    >> Thanks to both of you for the quick help anyway

    >
    > Now that you've got it compiling, you might want to stop it from crashing,
    > also. :)
    >
    > You're using indexes from 1 through 20. In C++, arrays are indexed
    > starting at 0, not 1. Your loops need to start at 0 and only continue
    > while the index is _less_than_ 20.
    >
    > -Howard
    >
    >
    >
    >>

    >
    >
     
    Andreas Schmitt, Jul 29, 2005
    #7
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ABC
    Replies:
    3
    Views:
    5,409
    Steve C. Orr [MVP, MCSD]
    Mar 29, 2006
  2. James via JavaKB.com

    Calling methods from within another class.

    James via JavaKB.com, Mar 28, 2005, in forum: Java
    Replies:
    0
    Views:
    491
    James via JavaKB.com
    Mar 28, 2005
  3. James via JavaKB.com

    Calling methods from within another class.

    James via JavaKB.com, Mar 28, 2005, in forum: Java
    Replies:
    4
    Views:
    801
    James via JavaKB.com
    Mar 31, 2005
  4. Bora Eryilmaz
    Replies:
    1
    Views:
    434
    Victor Bazarov
    Apr 18, 2005
  5. momo898
    Replies:
    2
    Views:
    611
    bruce barker \(sqlwork.com\)
    Oct 12, 2006
  6. DiesIrae
    Replies:
    3
    Views:
    187
    Brian Sheehan
    Sep 3, 2004
  7. torbs
    Replies:
    1
    Views:
    213
  8. bizt
    Replies:
    5
    Views:
    310
Loading...