# XCODE question



## xplicit (Mar 31, 2004)

hi guys,
question on X11...i created a stack class and am trying to use throw exception as part of the program. unfortunately, i am getting errors when i compile in X11. i used the same exact code in visual c++ and received no errors. i was hoping someone could steer me in the right direction. here is the code and errors that i am receiving when compiling:
StackException.h file
#include <exception>
#include <string>
using namespace std;

class StackException: public exception //is this inheritance??
{

public:
	StackException(const string &message=""): exception(message.c_str())
{

}
};
StackA.h file
#include "StackException.h"
typedef int StackItemType;
const int MAX_STACK = 20;

class Stack
{
public:
	Stack();
	bool isEmpty() const; 
	void push(StackItemType newItem) throw(StackException); 
	void pop() throw(StackException); 
	void pop(StackItemType &stackTop) throw(StackException); 
	void getTop(StackItemType &stackTop) const throw(StackException); 

private:
		char items[MAX_STACK];
		int top;
};

Errors when I compile cpp files:
exception:55: error:                 std::exception::exception()
exception:53: error: candidates are: std::exception::exception(const std::exception&)
StackA.cpp:51: error: declaration of `void Stack::getTop(StackItemType&) const' throws different exceptions
StackA.cpp:27: error: declaration of `void Stack:op()' throws different exceptions
StackA.cpp:38: error: declaration of `void Stack:op(StackItemType&)' throws different exceptions
StackA.cpp:14: error: declaration of `void Stack:ush(int)' throws different exceptions
StackException.h:10: error: no matching function for call to `std::exception::exception(const char*)'
StackA.h:13: error: than previous declaration `void Stack::getTop(StackItemType&) const throw (StackException)'
StackA.h:11: error: than previous declaration `void Stack:op() throw (StackException)'
StackA.h:12: error: than previous declaration `void Stack:op(StackItemType&) throw (StackException)'
StackA.h:10: error: than previous declaration `void Stack:ush(int) throw (StackException)'

Thks....


----------



## jove (Apr 4, 2004)

Yes it is inheritance.
You may need to put "std::", public : std::exception
Our std::exception constructor does not take any arguments (open Project->Show Class Browser). You have to supply your own string storage and override "what".
Why are you creating a stack class when there are "std::vector", "std::list", and other already built container classes?
Don't use throw specifications, they are only partially implemented and don't do much. If you really want to use them, you need a catch ( ... ) in the function implimentation and on catch throw only your custom exception.


----------



## wadesworld (Apr 5, 2004)

Don't compare ANYTHING to MSVC.  MSVC will compile almost anything, without complaint.  By far the compiler that adheres best to the standards is CodeWarrior, followed by gcc, followed way behind by MSVC.

We've uncovered countless bugs that CodeWarrior flagged and MSVC compiled without complaint.

Wade


----------



## xplicit (Apr 7, 2004)

jove said:
			
		

> Yes it is inheritance.
> You may need to put "std::", public : std::exception
> Our std::exception constructor does not take any arguments (open Project->Show Class Browser). You have to supply your own string storage and override "what".
> Why are you creating a stack class when there are "std::vector", "std::list", and other already built container classes?
> Don't use throw specifications, they are only partially implemented and don't do much. If you really want to use them, you need a catch ( ... ) in the function implimentation and on catch throw only your custom exception.



hi jove, i followed the part you mentioned about using std::exception...it got me less errors than before. unfortunately the error i am getting now seems to be ambigous...here it is:
StackException.h:10: error: parse error before `&' token
and here is my header file:
#include <exception>
#include <string>



class StackException: public std::exception

{	
public:
	StackException(const string &message=""): exception(message.c_str());

};

so i'm not really sure why i'm getting those errors.

i'm creating my own class coz i'm doing this for a class i'm taking. like i mentioned before, everything works in msvc but not in xcode...i should say everything works in xcode except the exception part....
also, i'm not sure what the rest of your intial reply meant. could you explain a bit more?

appreciate your help...xplicit


----------



## jove (Apr 7, 2004)

The only & in the sample code is between string and message. The token before & is string. It does not know what string is. Make certain you #include <string> (or any other class you use, remove any "using namespace" from header files (bad programming style), and place the std:: before any standard template library typenames you use. Namespaces are like directories for program symbols. The "directory" std (standard template library) contains string. :: is used as the directory separator like / is used for the filesystem.


----------

