Thread: Prob with pure virtual func (i think)

  1. #1
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72

    Prob with pure virtual func (i think)

    Hey

    Im restructuring a direct x program written in c++. Im calling a function called render which is a pure virtual function. The parent is GfxEntity and its child GfxEntitySprite has the implimentation of this function. When i call it in another class i get the error ''Render' : undeclared identifier'. Ive included them right i think so i dunno why i am having the problem. Here's some code.

    in GfxEntity:

    Code:
    virtual void Render(const D3DXVECTOR3 *pos)=0;
    in GfxEntitySprite:

    Code:
    void CGfxEntitySprite::Render(const D3DXVECTOR3 *pos)
    {
    
    ...
    
    }
    and the call from Visualisation:

    Code:
    Render(&pos);
    I have included the .h's for GfxEntity and GfxEntitySprite in Visualisation.h so i dunno why it cant see it. Any ideas?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    You're really going to have to post some more code.

  3. #3
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    erm ok. i dunno whats gonna help tho.

    The render function:

    Code:
    void CGfxEntitySprite::Render(const D3DXVECTOR3 *pos)
    {
    D3DXVECTOR2 pos2d=*pos;
    
    m_sprite->Begin();
    m_sprite->Draw(m_texture, NULL, NULL, NULL, 3.14f, &pos2d, 0xFFFFFFFF);
    m_sprite->End();
    }
    Call from vis:

    Code:
    void CVisualisation::RenderEntity(int id, const D3DXVECTOR3 *pos)
    {
    gD3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 0, 0);
    gD3dDevice->BeginScene();
    
    Render(&pos);
    
    gD3dDevice->EndScene();
    gD3dDevice->Present(NULL, NULL, NULL, NULL);	
    }
    .h declaration of class CGfxEntitySprite

    Code:
    class CGfxEntitySprite : public CGfxEntity  
    {
    public:
    	CGfxEntitySprite() {};
    	virtual ~CGfxEntitySprite() {};
    
    	bool InitialiseSprite(const char* textureFilename);
    	void Render(const D3DXVECTOR3 *pos);
    
    private:
    	LPD3DXSPRITE m_sprite;
    	LPDIRECT3DTEXTURE9 m_texture;
    	D3DXVECTOR3 pos;
    
    };

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well all i can see from code posted is that you are not calling Render through an object. Does CVisualization publically inherit from CGfxEntity or CGfxEntitySprite ? If not you will need to call Render thru an object. The compiler sees that call as a call to a global function Render and rightly complains because it doesnt exist.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Registered User gazsux's Avatar
    Join Date
    Mar 2002
    Posts
    72
    visualisation doesnt inherit from either of the two classes. how would i call it through an object? make an instance of the class GfxEntitySprite. then do something like GfxEntitySprite.Render() ?

  6. #6
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    yep. something like that. Depends on what constructors that class supports.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 10-28-2009, 09:25 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Information Regarding Pure Virtual Functions
    By shiv_tech_quest in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2003, 04:43 AM
  4. C++ XML Class
    By edwardtisdale in forum C++ Programming
    Replies: 0
    Last Post: 12-10-2001, 11:14 PM
  5. virtual or pure virtual
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-01-2001, 07:19 PM