Sign in to follow this  

Casting iterator annoyance!

This topic is 4823 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, I'm having problems casting the following in my object manager which I use to render D3D objects : This is the .cpp file
void CObjectManager::CreateCube()
{
	CCube* pCube = new CCube( m_pDevice, 0, 0, 0 );
	pCube->Initialise();
	m_Cube.push_back( pCube );
}

void CObjectManager::RenderObjects()
{
	for( std::vector<CCube*>::const_iterator viter_ = m_Cube.begin(); viter_ != m_Cube.end(); ++viter_ )
	{
		CCube* pCube = (CCube*)viter_;
	}
}

This is the .h file :
class CObjectManager
{
public:
	CObjectManager(LPDIRECT3DDEVICE9 pDevice);
	virtual ~CObjectManager(void);
	void RenderObjects();
	void CreateCube();
private:
	std::vector<CCube*> m_Cube;

	LPDIRECT3DDEVICE9 m_pDevice;

};

The error is on the RenderObjects method, I get the following error : error C2440: 'type cast' : cannot convert from 'std::vector<_Ty,_Ax>::const_iterator' to 'CCube *' with [ _Ty=CCube *, _Ax=std::allocator<CCube *> ] The line in question is : CCube* pCube = (CCube*)viter_; Any ideas ? Thanks, Steve

Share this post


Link to post
Share on other sites
Thanks Drunken Hyena,

That works a treat ;-)

Sorry for posting it in here, I've posted a lot of posts tonight all in this forum and forgot to change forum.

Share this post


Link to post
Share on other sites

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