Question about exceptions in C++ via Xcode

C

cipher

Guest
hi guys,
i'm currently working on my CS degree and have been using Visual C++. I just got an ibook and am using Xcode to create my applications. My question is about using exceptions in programs via Xcode. I created an application that includes some throw exception code in it. Whenever i try to compile and build in Xcode, I get a few errors returned to me. But when I try to compile and build the same exact code in Visual C++ it works perfectly. I was hoping someone could steer me in the right direction. I'll post the header files i'm using and the errors returned to me in this thread:

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:eek:p()' throws different exceptions
StackA.cpp:38: error: declaration of `void Stack:eek:p(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:eek:p() throw (StackException)'
StackA.h:12: error: than previous declaration `void Stack:eek:p(StackItemType&) throw (StackException)'
StackA.h:10: error: than previous declaration `void Stack:ush(int) throw (StackException)'

Thks....
 
OP
R

redhotdaddy

Guest
Bad C++ compiling in Xcode

Im also getting bad compiling errors when trying to compile C++ written code in XCode.

for example even when I do a g++ compile in terminal, i get the same errors as in Xcode. But the errors seem to be incongruent with C++ programming style. Look at my code followed by the errors. Any suggestions would be monumental!!! I have a C++ programming class and if I can get the C++ compiler to work I would be in heaven.


int main () {
string word[]={"Arizona","walk","government","C++","beach");
int wordsize = sizeof(word)/sizeof(string), i;
for (int j=0;j<wordsize;j++)
cout<<word[j]<<" ";
cout << endln;
//now pass each word to numberVowels
for (i=0;i<wordsize;i++)
{
cout<<word<<": ",,numberVowels(word)<<" vowels"<<endl;
firstLast(word);
}
return 0;
}


-----

main.cpp: In function `int main()':
main.cpp:12: error: parse error before `)' token
main.cpp:13: error: `i' undeclared (first use this function)


the latter errors seem to be errors that wouldnt be flagged in a C++ compiler. Am I wrong?
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
Here is what I see. First you defined the type of j efore using it, but not i. Second the following statement is unbalanced:

string word[]={"Arizona","walk","government","C++","beach");

If you count the number of brackets verses parentheses.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top