• Advertisement
Sign in to follow this  

Cannot instantiate abstract class...

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

Hi My plan was to right a simple basemesh class from which all my renderable classes are based off. That class should be abstract because it contains a virtual render function...my grid class is a child of this basemesh class and i defined a Grid::render() function but i can't create an instance of this class...and the compiler says the grid class would be abstract though i defined the render function and i don't understand why... CBaseMesh:
class CBaseMesh
{
public:
	DWORD FVF;
	LPDIRECT3DVERTEXBUFFER9 pVBuffer;	
	LPDIRECT3DINDEXBUFFER9 pIBuffer;
	virtual void render() const=0;
	CBaseMesh(void);
	~CBaseMesh(void);
};


Grid.h:
class Grid :
	public CBaseMesh
{
private:
	ngEngine *m_pEngine;
	int GetIndex(int x,int z){ return z*m_xRes+x;}
	void CreateVertices(D3DXVECTOR3 StartPoint,float RowHeight,float ColWidth,int xCount,int zCount);
	void CreateIndices(int xRes,int yRes);
	void ConstructBuffers();
public:
	int m_xRes,m_zRes;
	std::vector<GridVert> Verts;
	std::vector<short> Indices;
	void Create(ngEngine *engine,D3DXVECTOR3 StartPoint,float XSize,float ZSize,int xRes,int yRes);
	void render();
	Grid(void);
	~Grid(void);
};

[/soruce]

Grid::render:

void Grid::render() 
{	m_pEngine->g_pD3DDevice->SetRenderState(D3DRS_FILLMODE,D3DFILL_WIREFRAME);
	m_pEngine->g_pD3DDevice->SetFVF(FVF);
	m_pEngine->g_pD3DDevice->SetStreamSource(0,pVBuffer,0,sizeof(std::vector<GridVert>::value_type));
	m_pEngine->g_pD3DDevice->SetIndices(pIBuffer);
	m_pEngine->g_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,Verts.size(),0,(m_xRes-1)*(m_zRes-1)*2);
	//m_pEngine->g_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,4,0,2);
	//m_pEngine->g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
}

regards, m4gnus

Share this post


Link to post
Share on other sites
Advertisement
Remove the const specifier on the pure virtual function.

virtual void render() const = 0;
virtual void render() = 0;


Greetz,

Illco

Share this post


Link to post
Share on other sites
Your "Render" function prototypes do not match - one is const and one isn't, either remove the const from the base or add it to the derived.

Jans.

Share this post


Link to post
Share on other sites
ok that was the problem thank you

regards,
m4gnus

Share this post


Link to post
Share on other sites
Chances are you'll at some point find yourself having destructor problems aswell.
I recommend that you make ~CBaseMesh virtual, if you don't know why then [google] up on virtual destructors in base classes.

note: you don't need to explicitly state void for empty constructor parameters just () will do, just like the others. [smile]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement