By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,127 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,127 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
************************************************** *****************************************
Jul 28 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a

"Andreas Schmitt" <Ke**********@gmx.de> schrieb im Newsbeitrag
news:dc*************@news.t-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
************************************************** **************************
***************

Jul 28 '05 #2

P: n/a
Ian
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
Jul 28 '05 #3

P: n/a

"Ian" <no***@nowhere.com> schrieb im Newsbeitrag
news:11***************@drone2-svc-skyt.qsi.net.nz...
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
Jul 28 '05 #4

P: n/a
Ian
Andreas Schmitt wrote:
"Ian" <no***@nowhere.com> schrieb im Newsbeitrag
news:11***************@drone2-svc-skyt.qsi.net.nz...
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
Jul 28 '05 #5

P: n/a

"Andreas Schmitt" <Ke**********@gmx.de> wrote in message
news:dc*************@news.t-online.com...

"Ian" <no***@nowhere.com> schrieb im Newsbeitrag
news:11***************@drone2-svc-skyt.qsi.net.nz...
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

Jul 28 '05 #6

P: n/a
Eeeek!
You're right of course. Thanks
Will do

"Howard" <al*****@hotmail.com> schrieb im Newsbeitrag
news:nQ*********************@bgtnsc04-news.ops.worldnet.att.net...

"Andreas Schmitt" <Ke**********@gmx.de> wrote in message
news:dc*************@news.t-online.com...

"Ian" <no***@nowhere.com> schrieb im Newsbeitrag
news:11***************@drone2-svc-skyt.qsi.net.nz...
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


Jul 29 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.