Jump to content

  • Log In with Google      Sign In   
  • Create Account

Weird pointer problem


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
6 replies to this topic

#1   Members   

122
Like
Likes
Like

Posted 09 August 2001 - 06:36 AM

Basically, I have three classes: CWindow, CDirect3D, and CSprite. CWindow has a pointer to a CDirect3D object, and CDirect3D has a function, GetSprite(int), that returns a pointer to a CSprite based on the index given in GetSprite(). In my WndProc function (in CWindow, actually), I have the following code chunk:
	case WM_KEYDOWN:
		D3DXVECTOR2 move;
		ZeroMemory(&move, sizeof(D3DXVECTOR2));
		switch(wParam)
		{
		case VK_ESCAPE:
			PostQuitMessage(0);
			return 0;
		case VK_UP:
			move.y -= 1;
			break;
		case VK_DOWN:
			move.y += 1;
			break;
		case VK_LEFT:
			move.x -= 1;
			break;
		case VK_RIGHT:
			move.x += 1;
			break;
		}
		CSprite* pSprite;
		pSprite = m_pD3D->GetSprite(0); //ERROR
		pSprite->Move(&move);
 
The line marked //ERROR causes the following error in the compiler: error C2227: left of ''->GetSprite'' must point to class/struct/union I don''t see anything wrong...any suggestions? -Normie I am a devout follower of the "Lazy Programmer''s Doctrime"™... and I''m damned proud of it, too! ----- "I came, I saw, I started making games." ... If you''ll excuse me, I must resume my search for my long lost lobotomy stitches.

#2   Members   

572
Like
Likes
Like

Posted 09 August 2001 - 06:59 AM

Can you post the part where you declare m_pD3D ? and how you pass it to the function?

#3   Members   

122
Like
Likes
Like

Posted 09 August 2001 - 07:17 AM

OK...don''t blame me for spamminess, though
Here is the CWindow class, which contains the m_pD3D in question:

#include "Direct3D.h"

class CWindow
{
public:
void SetD3D(CDirect3D* pD3D);
int CheckMessages();
CWindow(HINSTANCE app, char* title);
static LRESULT CALLBACK WndProc(HWND window, UINT msg, WPARAM wParam, LPARAM lParam);
CWindow();
virtual ~CWindow();
static HWND GetWindow() {return m_window;}

private:
static HWND m_window;
CDirect3D* m_pD3D;
};

And here is where it is set (in WinMain):

CWindow window(hInstance, "Doodling");
CDirect3D d3d;
window.SetD3D(&d3d);



I am a devout follower of the
"Lazy Programmer''s Doctrime"™...
and I''m damned proud of it, too!
-----
"I came, I saw, I started making
games." ... If you''ll excuse
me, I must resume my search
for my long lost lobotomy stitches.

#4   Members   

100
Like
Likes
Like

Posted 09 August 2001 - 07:53 AM

Since your "WndProc" method is static it cannot access non static members of your class.

#5 Anonymous Poster_Anonymous Poster_*   Guests   

Likes

Posted 09 August 2001 - 08:13 AM

Looks like you have 2 problems:

1)The error message you''re getting means that you need to include your CDirect3D header file in your CWindow source file.

2)The other problem is like Prosper said, you can''t access m_pD3D from your WndProc function because the function is static and m_pD3D isn''t.

#6   Members   

127
Like
Likes
Like

Posted 09 August 2001 - 08:13 AM

Looks like you have 2 problems:

1)The error message you''re getting means that you need to include your CDirect3D header file in your CWindow source file.

2)The other problem is like Prosper said, you can''t access m_pD3D from your WndProc function because the function is static and m_pD3D isn''t.

#7   Members   

122
Like
Likes
Like

Posted 09 August 2001 - 08:39 AM

oh...er, um...whoops.
Kind of a misleading error message, though >

I am a devout follower of the
"Lazy Programmer''s Doctrime"™...
and I''m damned proud of it, too!
-----
"I came, I saw, I started making
games." ... If you''ll excuse
me, I must resume my search
for my long lost lobotomy stitches.




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.