Archived

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

Alright.. whats going on.. (classes)

This topic is 4946 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive got Direct X.h with a class DISPLAY, with functions defined in DISPLAY.cpp . Everything works fine. Now, As I try to add a TEXT class as a friend of DISPLAY, I''m getting loads of errors. I''m defining the TEXT functions in a TEXT.cpp which: #include "Direct X.h", just like DISPLAY.cpp does. any source file i try to compile generates errors and points to Direct X.h:
#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <d3dxsprite.h>

extern LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);

class DISPLAY
{
	friend class TEXT;
public:
        blah;
private:
	blah;
};

class SOUND
{
};

class TEXT{
public:
	TEXT(void);

	void TDrawText(char Text[50],D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale);
	void TDrawText(int Number,D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale);
	void TDrawText(float Number,int specifity,D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale);
	void TDrawText(double Number,int specifity,D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale);

	~TEXT(void);
private:
	IDirect3DTexture9 *FontTexture;
	RECT *FontRects[63];
};
Again DISPLAY was having no problems until i declared the third class. Now it, along with every source in my project flags the lines " TEXT(void);, with error C2208: ''void'' : no members defined using this type" heres the DISPLAY.cpp

#include "Direct X.h"

TEXT::TEXT(void)
{
	D3DXIMAGE_INFO imageInfo;
	int temp;

	tester=D3DXGetImageInfoFromFile("Font.bmp", &imageInfo);
	if FAILED (tester)
	{
		MessageBox(window, "Font File Not Found", "Error!",MB_ICONEXCLAMATION | MB_OK);
		return;
	}

	tester=D3DXCreateTextureFromFileEx(
		DISPLAY::D3DRenderDevice,
		"Font.bmp",
		imageInfo.Width,imageInfo.Height,
		1,//0,

		0,//D3DUSAGE_RENDERTARGET,//??

		D3DFMT_UNKNOWN,
		D3DPOOL_DEFAULT,
		D3DX_DEFAULT ,//D3DTEXF_NONE,

		D3DX_DEFAULT ,//D3DTEXF_NONE,

		D3DCOLOR_ARGB(255,0,0,0),
		NULL,NULL,
		FontTexture
		);

	if(FAILED(tester))
	{
		MessageBox(window, "Failed to load texture!", "Error!",MB_ICONEXCLAMATION | MB_OK);
		return;
	}
	for (temp=0;temp<26;temp++)//caps

	{
		FontRects[temp].top=0;
		FontRects[temp].bottom=27;
		FontRects[temp].left=(temp)*21;
		FontRects[temp].right=(temp+1)*21;
	}
	for(temp=27;temp<52;temp++)//lower case

	{
		FontRects[temp].top=35;
		FontRects[temp].bottom=65;
		FontRects[temp].left=(temp-27)*15;
		FontRects[temp].right=(temp-26)*15;
	}
	for(temp=53;temp<63;temp++)//numbers

	{
		FontRects[temp].top=35;
		FontRects[temp].bottom=65;
		FontRects[temp].left=(temp-27)*17;
		FontRects[temp].right=(temp-26)*17;
	}	

}


void TEXT::TDrawText(char Text[50],D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale)
{
	RECT *source;
	int index=0;
	while(true)
	{
		if(Text[index]==32)
			source=FontRects[62];
		else if(Text[index]==46)
			source=FontRects[61];
		else if(Text[index]>=48&&Text[index]<=57)
			source=FontRects[Text[index]+5];
		else if(Text[index]>=65&&Text[index]<=90)
			source=FontRects[Text[index]-65];
		else if(Text[index]>=97&&Text[index]<=122)
			source=FontRects[Text[index]-70];
		else break;
		DISPLAY::DrawSpriteToBuffer(FontTexture,screen_position,source,scale,NULL,NULL);
		index++;
	}
}

void TEXT::TDrawText(int Number,D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale)
{
	RECT *source;
	int temp=Number,length=0;
	
	while(temp>1)
	{
		length++;
		temp/=10;
	}

	int *number=new int[length];

	for(temp=length-1;temp>=0;temp--)
	{
		number[temp]=Number%10;
		Number-=number[temp];
		Number/=10;
	}

	for(temp=0;temp<length;temp++)
	{
		source=FontRects[number[temp+53]];
		DISPLAY::DrawSpriteToBuffer(FontTexture,screen_position,source,scale,NULL,NULL);
	}
}

void TEXT::TDrawText(float Number,int specifity,D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale)
{
}

void TEXT::TDrawText(double Number,int specifity,D3DXVECTOR2 *screen_position,D3DXVECTOR2 *scale)
{
}

TEXT::~TEXT(void)
{
}
Now im guessing it has something to do with the way im linking all my files together... (This is the first time ive had two classes spanned over three files) or maybe theres some extremly obvious problem that im just not seeing..

Share this post


Link to post
Share on other sites
thanks for the responce but msdn has an example (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccelng/htm/cntrl_10.asp) almost identical to my .h up there (in terms of class and friend placements), ill try rearanging some stuff anyway.

edit:yea, moving text above display has no effect

[edited by - unliterate on May 29, 2004 12:15:43 AM]

Share this post


Link to post
Share on other sites
IIRC, function_name(void) is not standard C++. It used to be valid in C, but not in C++, so I would suggest using TEXT() and ~TEXT() instead. See if that works.

Share this post


Link to post
Share on other sites
Do you mean in the .h or the .cpp or both? taking void out of both results with :

error C2059: syntax error : ';'
error C2238: unexpected token(s) preceding ';'

both on line :
~TEXT();


the latter error occuring no matter what i do.

edit: oh, its spose to be in the .cpp but not the header. but doing this results in:

error C2208: 'void' : no members defined using this type
on line 'TEXT(void);'

and :

error C2062: type 'void' unexpected
error C2238: unexpected token(s) preceding ';'

on line '~TEXT(void);'

(these errors are in the header)

edit2:
or maybe its not supposed to be anywhere, i dont know :-/ no combination works.

[edited by - unliterate on May 29, 2004 12:38:10 AM]

Share this post


Link to post
Share on other sites
Im also getting error C2352: 'DISPLAY::DrawSpriteToBuffer' : illegal call of non-static member function. and quite a few syntax errors. Im off to bed, maybe im just too tired right now.

[edited by - unliterate on May 29, 2004 12:53:14 AM]

Share this post


Link to post
Share on other sites
I agree with Doc, I''d say both. Constructors (that take no arguments) and destructors don''t use void. In some senses it can be seen as a break with convention of parameter declarations but that''s how it goes. I''ve never used void in this context and I wouldn''t know what happens if you do.

If that doesn''t work try something like this.


class TEXT;

class DISPLAY{
public:
DISPLAY();
~DISPLAY();
...
friend class TEXT;
...
};

TEXT::TEXT()
{
...
}

TEXT::~TEXT()
{
...
}


And if that doesn''t work I''d try renaming TEXT because I''ve seen that used as some sort of string declaration macro in the DirectX samples (I couldn''t find it''s declaration in a 30 second search).

R

--------------------------------------------------------------------------
There is no point in flaming if you''ve merely poured fuel on your own head

Share this post


Link to post
Share on other sites
Now for some errors i feel i should actually be getting, Im still learning classes so why is it when i do something like:

DISPLAY::tester=D3DXGetImageInfoFromFile("Font.bmp", &imageInfo);
in a (now) D3DTEXT member function?

i get:
error C2597: illegal reference to data member 'DISPLAY::tester' in a static member function

(im not sure what the error means)

[edited by - unliterate on May 30, 2004 1:36:15 AM]

Share this post


Link to post
Share on other sites
Not a problem.

Hmm, how do you declare "tester" ? Is it static ? Wouldn''t you need an instance of DISPLAY in order to set tester if it isn''t static ?

I went to the M$ web site and did a search on C2597. The first entry in the results gives this page:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/c2597.asp

R

--------------------------------------------------------------------------
There is no point in flaming if you''ve merely poured fuel on your own head

Share this post


Link to post
Share on other sites
ooh. I need the instance of the DISPLAY class for which i want to modify the value i guess.

edit: hadnt seen your post , yea, not sure what i was thinking. (this is my first time using 'friends')

[edited by - unliterate on May 30, 2004 1:54:20 AM]

Share this post


Link to post
Share on other sites