Errors.... stupid errors

Started by
2 comments, last by cmptrgear 18 years ago
Okay, I use Dev C++ and I get these errors when I compile the below code: Compiler: Default compiler Building Makefile: "C:\Dev-Cpp\projects\1\Makefile.win" Executing make... make.exe -f "C:\Dev-Cpp\projects\1\Makefile.win" all g++.exe -c StateMan.cpp -o StateMan.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include" In file included from StateMan.cpp:5: StateMan.h:30: error: ISO C++ forbids declaration of `stack' with no type StateMan.h:30: error: expected `;' before '<' token StateMan.cpp: At global scope: StateMan.cpp:24: error: expected unqualified-id before ':' token StateMan.cpp:24: error: expected `,' or `;' before ':' token StateMan.cpp:29: error: expected unqualified-id before ':' token StateMan.cpp:29: error: expected `,' or `;' before ':' token StateMan.cpp: In member function `void StateManager::Push(void (*)(int))': StateMan.cpp:37: error: `FunctionPtr' is not a type StateMan.cpp:37: error: request for member of non-aggregate type before '=' token StateMan.cpp:38: error: `Statelist' undeclared (first use this function) StateMan.cpp:38: error: (Each undeclared identifier is reported only once for each function it appears in.) StateMan.cpp: In member function `void StateManager::Pop()': StateMan.cpp:43: error: `Statelist' undeclared (first use this function) StateMan.cpp:44: error: type `struct tState' argument given to `delete', expected pointer StateMan.cpp:46: error: expected `;' before '}' token StateMan.cpp: In member function `bool StateManager::Process()': StateMan.cpp:50: error: `Statelist' undeclared (first use this function) StateMan.cpp: In member function `void StateManager::Clear()': StateMan.cpp:56: error: `Statelist' undeclared (first use this function) make.exe: *** [StateMan.o] Error 1 Execution terminated Here is my code, one H file and CPP file are causing this

//Stack.h
//This is the StateManager
//Originally, I did not want to have to use a State Manager
//But since this is an SDKish thing it is good to have one. 
//It will also keep track of all my states for me, which is 
//handy.
//Austen Higgins-Cassidy
#include <cstdlib>
#include <string>

#include <stack>

#ifndef _STATEMAN_H_
#define _STATEMAN_H_

struct tState
{
   
      void (*FunctionPtr)(int flag);
      
      tState();
      ~tState();
      tState(const tState &RHS);
};


class StateManager
{
      private:
      stack<tState> Statelist;
      public:
      StateManager();
      ~StateManager();
      
      void Push(void (*FunctionPtr)(int));
      void Pop();
      bool Process();
      void Clear();
      
};

#endif



and the Cpp file

//StateMan.cpp
#include <cstdlib>
#include <string>
#include <stack>
#include "StateMan.h"

using namespace std;

tState::tState()
{
FunctionPtr = NULL;
}

tState::~tState()
{

}

tState::tState(const tState &RHS)
{
FunctionPtr = RHS.FunctionPtr;
}

StateManager:StateManager()
{
Statelist.clear();
}

StateManager:~StateManager()
{
Clear();
}

void StateManager::Push(void (*FunctionPtr)(int))
{
tState *StatePtr = new tState;
StatePtr->FunctionPtr = FunctionPtr;
Statelist.push(StatePtr);
}

void StateManager::Pop()
{
tState *StatePtr = Statelist.top();
delete *StatePtr;
Statelist.pop()
}

bool StateManager::Process()
{
     tState *StatePtr = Statelist.top();
     StatePtr->FunctionPtr;
}

void StateManager::Clear()
{
     while(!Statelist.empty())
     {
     Pop();
     }
}



[Edited by - Plasmarobo on April 1, 2006 2:37:50 PM]
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be
Advertisement
stack in the header file isn't being found in the right namespace. You can move the using namespace std; to before the #include "StateMan.h" to fix that.

Or, even better, get rid of the icky using namespace std and qualify stack as std::stack.


A couple places you've used a single : instead of :: when defining a class member function.

That should fix a good chunk, if not all, of your errors.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanx, that helped alot, but for some reason my program will not allow me to make a pointer to tState.... which is annoying, since I need them.
I get this error:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\projects\1\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\projects\1\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"

g++.exe -c StateMan.cpp -o StateMan.o -I"lib/gcc/mingw32/3.4.2/include" -I"include/c++/3.4.2/backward" -I"include/c++/3.4.2/mingw32" -I"include/c++/3.4.2" -I"include"

StateMan.cpp: In member function `void StateManager::Pop()':
StateMan.cpp:44: error: cannot convert `tState' to `tState*' in initialization

StateMan.cpp: In member function `bool StateManager::Process()':
StateMan.cpp:51: error: cannot convert `tState' to `tState*' in initialization

make.exe: *** [StateMan.o] Error 1

Execution terminated

well, it is actually 2 errors.
Here is my new source:
h file:
//Stack.h//This is the StateManager//Originally, I did not want to have to use a State Manager//But since this is an SDKish thing it is good to have one. //It will also keep track of all my states for me, which is //handy.//Austen Higgins-Cassidy#include <cstdlib>#include <string>#include <stack>#ifndef _STATEMAN_H_#define _STATEMAN_H_struct tState{         void (*FunctionPtr)(int flag);            tState();      ~tState();      tState(const tState &RHS);};class StateManager{      private:      stack<tState> Statelist;      public:      StateManager();      ~StateManager();            void Push(void (*FunctionPtr)(int));      void Pop();      bool Process();      void Clear();      };#endif


And here is the cpp file
//StateMan.cpp#include <cstdlib>#include <string>#include <stack>using namespace std;#include "StateMan.h"tState::tState(){FunctionPtr = NULL;}tState::~tState(){}tState::tState(const tState &RHS){FunctionPtr = RHS.FunctionPtr;}StateManager::StateManager(){Clear();}StateManager::~StateManager(){Clear();}void StateManager::Push(void (*FunctionPtr)(int)){tState *StatePtr = new tState;StatePtr->FunctionPtr = FunctionPtr;Statelist.push(*StatePtr);}void StateManager::Pop(){tState *StatePtr = Statelist.top();Statelist.pop();delete StatePtr;}bool StateManager::Process(){     tState *StatePtr = Statelist.top();     StatePtr->FunctionPtr;}void StateManager::Clear(){     while(!Statelist.empty())     {     Pop();     }}

Thanks...
___________________________________________________Optimists see the glass as Half FullPessimists See the glass as Half EmptyEngineers See the glass as Twice as big as it needs to be
your statelist variable holds tState objects not tState * objects. You would need to do something like
tState * ptState = &(statelist.top());
to get the pointer.

Or you could store pointers to begin with which is a better idea
stack<tState *> stateList;
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson

This topic is closed to new replies.

Advertisement