Archived

This topic is now archived and is closed to further replies.

Normie

Weird pointer problem

Recommended Posts

Normie    122
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"(tm)... 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.

Share this post


Link to post
Share on other sites
Normie    122
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"(tm)...
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
JonStelly    127
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.

Share this post


Link to post
Share on other sites
Normie    122
oh...er, um...whoops.
Kind of a misleading error message, though >

I am a devout follower of the
"Lazy Programmer''s Doctrime"(tm)...
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.

Share this post


Link to post
Share on other sites