Sign in to follow this  

A sintax error with a structure..

This topic is 4355 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

I've tried to used this class:
//Font informations
struct bn_FontInformations
{
    //Width of the font
    int iWidth;

    //Weight of the font
    int iWeight;

    //Height of the font
    int iHeight;

    //Specifies the character set for example: TURKISH_CHARSET;DEFAULT_CHARSET
    int iCharSet;

    //Specifies the pitch and family of the font FF_DECORATIVE;FF_DONTCARE;FF_MODERN
    int iPitchAndFamily;

    //Tests if it's italic
    bool bItalic;

    //The name of the font
    char *pFontName;

};

//Class for the font 
class bn_Font 
{ 
    public:
 
        //Initialise DirectXGraphics
        bn_Font();

        //Desturktor clears the class
        ~bn_Font();

        //Initialise DirectXGraphics
        void Initialise(LPDIRECT3DDEVICE9 lpD3DDevice,bn_FontInformations FontInfo);
            
        //Draws the Text
        void DrawText(char *pText,int iX,int iY,int iWidth = 0,int iHeight = 0, D3DCOLOR TextColor = D3DCOLOR_XRGB(0xFF,0xFF,0));

        //If the device'll be reseted
        void OnLostDevice();    

        //If the device has been reseted
        void OnResetDevice();

    protected:

        //The font
        LPD3DXFONT m_lpD3DFont;

        //If it's initialised
        bool m_bInitialise;
}; 

inline void CopyPointingString(char *pTarget,char *pSource,int size)
{
    for(int i=0; i<size; i++)
    {
        if (i == size-1)
            pTarget[i]='\0';
        else
            pTarget[i]=pSource[i];
    }
}

//Initialise DirectXGraphics
bn_Font::bn_Font()
{
    //Sets it 0
    m_lpD3DFont        = NULL;
    m_bInitialise    = false;
}


//If the device'll be reseted
void bn_Font::OnLostDevice()
{    
    m_lpD3DFont->OnLostDevice();
}

//If the device has been reseted
void bn_Font::OnResetDevice()
{
    m_lpD3DFont->OnResetDevice();
}

//Initialise DirectXGraphics
void bn_Font::Initialise(LPDIRECT3DDEVICE9 lpD3DDevice,bn_FontInformations FontInfo)
{
    D3DXFONT_DESC FontDesc;
 
    if (FontInfo.pFontName)
        CopyPointingString(FontDesc.FaceName,FontInfo.pFontName,sizeof(FontInfo.pFontName));

    //Sets the informations
    FontDesc.Weight            = FontInfo.iWeight;
    FontDesc.Width             = FontInfo.iWidth;
    FontDesc.Height            = FontInfo.iHeight;
    FontDesc.CharSet           = FontInfo.iCharSet;
    FontDesc.PitchAndFamily    = FontInfo.iPitchAndFamily;
    FontDesc.Italic            = FontInfo.bItalic;
    FontDesc.MipLevels         = 1;

    //Creates the font
    D3DXCreateFontIndirect(lpD3DDevice,&FontDesc,&m_lpD3DFont);

    m_bInitialise = true;
}
 
//Destructor clears the class
bn_Font::~bn_Font()
{
    //Clean
    if (NULL != m_lpD3DFont)
    {
        m_lpD3DFont->Release();
        m_lpD3DFont = NULL;
    }
}

//Draws the Text
void bn_Font::DrawText(char *pText,int iX,int iY,int iWidth,int iHeight,D3DCOLOR TextColor)
{
    //Draws it
    if (m_bInitialise)
    {
        //Creates a buffer
        char strBuffer[255];

        sprintf(strBuffer,"%s",pText);

        RECT r = {iX,iY,iWidth,iHeight};

        //Sets the size
        if (iWidth == 0 || iHeight == 0)
            m_lpD3DFont->DrawText(NULL,strBuffer,-1,&r,DT_CALCRECT,TextColor);

        //Gives it out
        m_lpD3DFont->DrawText(NULL,strBuffer,-1,&r,DT_CENTER,TextColor);
    }
} 

So i want use this class in my new class:
class bn_Font;
class Game
{ 
public:
	Game(void);
	~Game(void);

	bool init(HWND wndHandle, D3DXVECTOR3 posCamera);
	void shutdown(void);

	int update();
	void render(void);
	void fontManagerInit(void);
	void fontManagerDraw(void);

private:

	LPDIRECT3DDEVICE9       pd3dDeviceGame;
	LPD3DXFONT				g_pd3dxFontGame;
	
	bool createGameObjects(void);
	
	// timer variables
	LARGE_INTEGER timeStart;
	LARGE_INTEGER timeEnd;
	LARGE_INTEGER timerFreq;


	float         anim_rate;
	int squadra;
	int squadra2;

	int contDestra;
	int contSinistra;
	int contDietro;
	int contAvanti;

	int matrix[5][5];
	int n_1,j_1,n_2,j_2;

	char mamtfc;

	// Pointer to a CShip object
	CShip		  *pShip;						// the player's spaceship
	Personaggio2  *pPersonaggio2;
	GestioneTurni *pGestTurni;
	bn_Font		  *pFont;


	// Pointer to a CPlanet object
	CPlanet *pPlanet;					// The main planet

	// The game objects vector
	// This vector will store all the in-game objects to be updated and rendered
	std::vector <CGameObject*> objects;

};

bool Game::init(HWND wndHandle, D3DXVECTOR3 posCamera)
{
	
....................

mamtfc = 'P';

	
	pFont->Initialise(g_pd3dxFontGame, 10, 10, 10, DEFAULT_CHARSET, FF_DONTCARE, FALSE, mamtfc);

	return true;
}
When i try to compile hit, i've this errors: error C2027: use of undefined type 'bn_Font' : see declaration of 'bn_Font' error C2227: left of '->Initialise' must point to class/struct/union I see that's a stupid errors for you, but i can't resolve this little problem. Anyone can help me? Thanks a lot.

Share this post


Link to post
Share on other sites
I'm moving this over to 'General Programming'. Whilst you're writing a DirectX program, it seems to me that your problem is just a general C/C++ issue rather than a DirectX specific one.

I personally don't have time to look through it in detail, but it seems you haven't specified which files those source fragments exist in. The error you descibe is typically one caused by messing up dependencies - e.g. failing to include the right file for example.

Maybe someone else will be able to shed some light on it [smile]

Jack

Share this post


Link to post
Share on other sites
The definition of class bn_Font must be "visible" at the point where you make use of such an object. Thus Game.cpp needs to #include "bn_font.h" (or whatever your actual file names are).

You should probably read this.

Share this post


Link to post
Share on other sites

This topic is 4355 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this