Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Problem with Calling Methods from Objects which are stored in an array from within another Object

Reply
Thread Tools

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

 
 
Andreas Schmitt
Guest
Posts: n/a
 
      07-28-2005
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
************************************************** *****************************************


 
Reply With Quote
 
 
 
 
Christian Meier
Guest
Posts: n/a
 
      07-28-2005

"Andreas Schmitt" <> schrieb im Newsbeitrag
news:dc9t5t$r9k$01$...
> 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
>

************************************************** **************************
***************
>
>



 
Reply With Quote
 
 
 
 
Ian
Guest
Posts: n/a
 
      07-28-2005
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
 
Reply With Quote
 
Andreas Schmitt
Guest
Posts: n/a
 
      07-28-2005

"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


 
Reply With Quote
 
Ian
Guest
Posts: n/a
 
      07-28-2005
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
 
Reply With Quote
 
Howard
Guest
Posts: n/a
 
      07-28-2005

"Andreas Schmitt" <> wrote in message
news:dca18m$1fh$02$...
>
> "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



>



 
Reply With Quote
 
Andreas Schmitt
Guest
Posts: n/a
 
      07-29-2005
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$...
>>
>> "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
>
>
>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing one objects methods from within another object Adam Akhtar Ruby 2 11-29-2008 07:28 AM
Calling internal 'public' methods within js objects bizt Javascript 5 05-22-2008 12:44 AM
Calling methods from within another class. James via JavaKB.com Java 4 03-31-2005 11:05 AM
Calling methods from within another class. James via JavaKB.com Java 1 03-28-2005 09:28 PM
Calling methods from within another class. James via JavaKB.com Java 0 03-28-2005 08:45 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57