Jump to content
  • Advertisement
Sign in to follow this  
Lennings

state manager problem, and some question.

This topic is 4322 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 trying to build a state manager but have some problem with my code. I don’t know exactly what’s wrong. The error started when I wanted to make my variable to a vector<T*> XXX;, it worked when I have T *XXX; I got the error.
Error C2679: binary '[' : no operator found which takes a right-hand operand of type 'const std::allocator<_Ty>::value_type' (or there is no acceptable conversion)
        with
        [
            _Ty=SceneStates *
        ]
I think it is in this function.
template<typename T>
T* StateManager<T>::getState(int stateIndex) const
{
	if(!m_states.empty())
		if(stateIndex < 0)
			return m_states[m_states.back()];
		else
			return m_states[stateIndex];
	else
		return NULL;
}
__________________________________________________________________ I got this error if I have the // line. Don’t know way. It is just a commentary. If I remove it the error will go away. fatal error C1075: end of file found before the left brace '{' at 'c:\Documents and Settings\Lennings\Skrivbord\Map Editor GL\Visual Studio .NET 2003\Map Editor GL\StateManager.h(86)' was matched
template<typename T>
void StateManager<T>::pushState(T* newState)
{
	// CAN’T GET CONTACT WITH m_states FROM HERE ???
}
__________________________________________________________________ I use mvc++ .NET 2003, and some times when I get an error and double click on it I get to another please then the error.. Have no clue why! And sometimes my variables don’t work with intellSense even that all seems to be ok. Don’t know if it is the program. ____________________________________________________________________ The whole class.
// CONTROLL THE STATE MANGERING.
#ifndef DEFINE_STATEMANAGER
#define DEFINE_STATEMANAGER
#include <iostream>
#include <vector>

template<typename T>
class StateManager
{
public:
    /*
    Description:
		THIS IS THE STATE MANGER CONSTRUKTOR.
    */  
	StateManager();

    /*
    Description:
		THIS IS THE STATE MANAGER DESTRUKTOR.
    */  
	~StateManager();

    /*
    Description:
		ADD A NEW STATE.
	Parameters:
		newState = THE NEW STATE.
    */  
	void pushState(T *newState);

    /*
    Description:
		DELETE THE LAST STATE.
    */  
	void popState();
   
    /*
    Description:
		GET THE POINTER TO A STATE.
	Parameters:
		stateIndex = WHICH STATE POINTER TO RETURN, -1 DEFAULT TO GET THE LAST STATE.
	Returns value:
		RETURN THE POINTER TO A STATE.
    */  
	T* getState(int stateIndex = -1) const;

    /*
    Description:
		SET THE LAST STATE TO A DEFFIERENT STATE.
	Parameters:
		newState = THE NEW STATE.
    */  
	void setState(T *newState);

	/*
    Description:
		HOW MANY STATES IS SAVED.
	Returns value:
		NUMBER OF STATES SAVED.
	*/
	unsigned int states();

	/*
    Description:
		DELETE A STATE.
	Parameters:
		stateIndex = WITCH STATE INDEX TO DELETE.
    */  
	void deleteState(int stateIndex);

private:
	std::vector<T*> m_states;	// STATE CONTAINER.
};

template<typename T>
StateManager<T>::StateManager()
{
}

template<typename T>
StateManager<T>::~StateManager()
{
	for(unsigned int index=0; index < m_states.size(); index++)
		delete m_states[index];
	m_states.clear();
}

template<typename T>
void StateManager<T>::pushState(T* newState)
{
	// CAN´T GET CONTACT WITH m_states FROM HERE ???
}

template<typename T>
void StateManager<T>::popState()
{
	delete m_states[m_states.back()];
	m_states.pop_back();
}

template<typename T>
T* StateManager<T>::getState(int stateIndex) const
{
	if(!m_states.empty())
		if(stateIndex < 0)
			return m_states[m_states.back()];
		else
			return m_states[stateIndex];
	else
		return NULL;
}

template<typename T>
void StateManager<T>::setState(T *newState)
{
	if(!m_states.empty())
	{
		delete m_states[m_states.back()];
		m_states[m_states.back()] = newState;
	}
	else
		m_states.push_back(newState);
}

template<typename T>
unsigned int StateManager<T>::states()
{
	return m_states.size();
}

template<typename T>
void StateManager<T>::deleteState(int stateIndex)
{
	if(!m_states.empty())
	{
		delete m_states[stateIndex];
		m_states.erase(stateIndex);
	}
}

#endif


____________________________________________________ Thants for all assistance. [edit: added code and source tags -SiCrane]

Share this post


Link to post
Share on other sites
Advertisement
Quote:

return m_states[m_states.back()];

This line could be the problem.
The back function returns the last item in the vector, not the index to the last item.
What you want here is probably just
return m_states.back();


Quote:

fatal error C1075: end of file found before the left brace '{' at 'c:\Documents and Settings\Lennings\Skrivbord\Map Editor GL\Visual Studio .NET 2003\Map Editor GL\StateManager.h(86)' was matched

This indicates that you are missing a left brace somewhere.
Missing bracets is very confusing for the compiler, so you are likely to get references to errors all over the place until you correct this one.

Share this post


Link to post
Share on other sites
thanks... is seems to work... but the // is a little weard.. but it works....


thanks for the help.... good to have some gurus when help is needed...

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!