Weird pointer problem

Started by
5 comments, last by Normie 22 years, 8 months ago
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.
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 makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.
Advertisement
Can you post the part where you declare m_pD3D ? and how you pass it to the function?
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.
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 makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.
Since your "WndProc" method is static it cannot access non static members of your class.
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.
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.
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.
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 makinggames." ... If you'll excuseme, I must resume my searchfor my long lost lobotomy stitches.

This topic is closed to new replies.

Advertisement