Puzzle: make new compilers understand what g++ 2.95.3 compiled

Discussion in 'C++' started by nospam_news@wanano.net, May 8, 2007.

  1. Guest

    When language changes make old code uncompilable, that's not what is
    called protection of investment.

    New compilers (g++ > 3.2.3) reject classes where methods throw the
    class they belong to.
    gcc 2.95.3 allowed it.

    What are the minimal modification, that leave the usage of the class
    sound and can be compiled by newer compilers.

    Thank you


    ( compile the following code with s.th. like g++ -g -o Exception
    Exception.cpp -lstlport_gcc )

    #include "iostream"

    class Exception {
    public:
    Exception(int);
    void setErrNo(int i) throw(Exception);
    int errNo;
    };

    Exception::Exception(int e) {
    errNo=e;
    }

    void Exception::setErrNo(int i) throw(Exception) {
    auto Exception methodException(2);
    errNo=i;
    throw(methodException);
    };

    int main(char argc, char *argv[], char *env[]) {
    try {
    auto Exception mainException(1);
    mainException.setErrNo(42);
    } catch (Exception caughtmainException) {
    std::cout << "caught mainException:" << mainException.errNo <<
    std::endl;
    }
    }
    , May 8, 2007
    #1
    1. Advertising

  2. On 8 Maj, 12:57, ""
    <> wrote:
    > When language changes make old code uncompilable, that's not what is
    > called protection of investment.
    >
    > New compilers (g++ > 3.2.3) reject classes where methods throw the
    > class they belong to.
    > gcc 2.95.3 allowed it.
    >
    > What are the minimal modification, that leave the usage of the class
    > sound and can be compiled by newer compilers.
    >
    > Thank you
    >
    > ( compile the following code with s.th. like g++ -g -o Exception
    > Exception.cpp -lstlport_gcc )
    >
    > #include "iostream"
    >
    > class Exception {
    > public:
    > Exception(int);
    > void setErrNo(int i) throw(Exception);
    > int errNo;
    >
    > };
    >
    > Exception::Exception(int e) {
    > errNo=e;
    >
    > }
    >
    > void Exception::setErrNo(int i) throw(Exception) {
    > auto Exception methodException(2);
    > errNo=i;
    > throw(methodException);
    >
    > };
    >
    > int main(char argc, char *argv[], char *env[]) {
    > try {
    > auto Exception mainException(1);
    > mainException.setErrNo(42);
    > } catch (Exception caughtmainException) {
    > std::cout << "caught mainException:" << mainException.errNo <<
    > std::endl;
    > }
    > }


    mainException is no longer in scope when you try to print errNo, are
    you sure you didn't mean

    td::cout << "caught mainException:" << caughtmainException.errNo <<
    std::endl;

    --
    Erik Wikström
    =?iso-8859-1?q?Erik_Wikstr=F6m?=, May 8, 2007
    #2
    1. Advertising

  3. Guest

    You are absolutely right.
    This should be corrected in the initial message.

    But that is not the real problem.

    Thank you for your attention
    , May 8, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Klaus Schneider
    Replies:
    1
    Views:
    530
    Rolf Magnus
    Dec 2, 2004
  2. geletine

    commercial c compilers vs free c compilers

    geletine, Jul 2, 2006, in forum: C Programming
    Replies:
    33
    Views:
    1,300
  3. Replies:
    5
    Views:
    281
    peter koch
    May 8, 2007
  4. lander
    Replies:
    5
    Views:
    580
    bruce barker
    Mar 5, 2008
  5. Juha Nieminen
    Replies:
    3
    Views:
    349
    Stuart
    Sep 21, 2012
Loading...

Share This Page