Sign in to follow this  
m4gnus

Cannot instantiate abstract class...

Recommended Posts

m4gnus    240
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
Illco    928
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
Jansic    251
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
dmatter    4844
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

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