Jump to content
  • Advertisement
Sign in to follow this  
steg

Casting iterator annoyance!

This topic is 5035 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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!