Sign in to follow this  
steg

Casting iterator annoyance!

Recommended Posts

steg    390
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
DrunkenHyena    805
I think that should be:

CCube* pCube = (CCube*)*viter_;

And this really has nothing to do with DirectX. General Programming would probably be a better forum for STL questions.

Share this post


Link to post
Share on other sites
steg    390
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

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