Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

odd const

Started by luasitdown 3 replies 350+ views
Original Post
luasitdown
luasitdown

void Node::validateHierarchy( bool forceUpdate ) const //   here are problem
{
	if ( (m_flag & NODE_WORLDDIRTY) || forceUpdate )
	{
		// compute model->world transform
		Node* parent = this->parent();
		if ( parent )
			m_worldTransform = parent->m_worldTransform * m_localTransform;
		else
			m_worldTransform = m_localTransform;
		
		m_flag &= ~NODE_WORLDDIRTY;
		forceUpdate = true;
	}

	std::vector<Node*>::iterator it, begin, end;
	begin = m_child.begin();//   here are problem
	end = m_child.end();

	for ( it = begin;it != end; it++)
		it.validateHierarchy( forceUpdate );
}

If I use const ,C2679 error up. why???
Sneftel
Sneftel
You can't get a non-const iterator to a const container.
JohnBolton
JohnBolton
A const member function automatically treats all member variables as const. Furthermore, you can only call other const member functions (or static member functions).
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Red Ant
Red Ant
Another thing:

// This is not good. You're using the post-increment operator even tho you// you're not interested in its return value at all. Use the more efficient// pre-incremement operator instead.//for ( it = begin;it != end; it++) // not goodfor ( it = begin;it != end; ++it ) // better		it.validateHierarchy( forceUpdate );

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.