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

A

Andreas Schmitt

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
*******************************************************************************************
 
C

Christian Meier

Andreas Schmitt said:
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.
 
I

Ian

Andreas said:
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
 
A

Andreas Schmitt

Ian said:
Andreas said:
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
 
I

Ian

Andreas said:
Andreas said:
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
 
H

Howard

Andreas Schmitt said:
Ian said:
Andreas said:
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
 
A

Andreas Schmitt

Eeeek!
You're right of course. Thanks
Will do

Howard said:
Andreas Schmitt said:
Ian said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top