Jump to content

  • Log In with Google      Sign In   
  • Create Account

Calling all IT Pros from Canada and Australia.. we need your help! Support our site by taking a quick sponsored surveyand win a chance at a $50 Amazon gift card. Click here to get started!


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 Normie   Members   -  Reputation: 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.

Sponsor:

#2 xEricx   Members   -  Reputation: 568

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 Normie   Members   -  Reputation: 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 Prosper/LOADED   Members   -  Reputation: 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   -  Reputation:

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 JonStelly   Members   -  Reputation: 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 Normie   Members   -  Reputation: 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.



PARTNERS