Results 1 to 3 of 3
  1. #1
    cipher
    Guest
    Question about exceptions in C++ via Xcode
    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 Stackp()' throws different exceptions
    StackA.cpp:38: error: declaration of `void Stackp(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 Stackp() throw (StackException)'
    StackA.h:12: error: than previous declaration `void Stackp(StackItemType&) throw (StackException)'
    StackA.h:10: error: than previous declaration `void Stack:ush(int) throw (StackException)'

    Thks....

  2. #2
    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[i]<<": ",,numberVowels(word[i])<<" vowels"<<endl;
    firstLast(word[i]);
    }
    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?

  3. #3
    Question about exceptions in C++ via Xcode
    rman's Avatar
    Member Since
    Dec 24, 2002
    Location
    Los Angeles, California
    Posts
    12,584
    Specs:
    2 x 3.0GHz Quad-Core, 6GB OS X 10.6.8 | 15in MacBook Pro 2.2GHz OS X 10.6.8 | 64GB iPad 2 WiFi
    Cool
    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.
    Life isn't about waiting for the storm to pass, It's about learning to dance in the rain!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Black Screen with Backtrace Exceptions
    By WebX in forum Apple Desktops
    Replies: 8
    Last Post: 03-21-2011, 12:20 PM
  2. Firmware password exceptions?
    By Giantegg in forum OS X - Operating System
    Replies: 6
    Last Post: 10-09-2009, 05:38 PM
  3. How to back up everything without exceptions?
    By tenp in forum OS X - Apps and Games
    Replies: 7
    Last Post: 03-24-2008, 05:25 PM
  4. Allowing Exceptions to Safari's Pop Up Blocker?
    By mac57 in forum OS X - Apps and Games
    Replies: 3
    Last Post: 03-30-2007, 12:41 AM
  5. How to trap fpu exceptions on macbook pro?
    By miggles in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 11-16-2006, 09:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •