Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Throw-oriented programming

Name: Anonymous 2010-08-24 8:59


#include <iostream>

using std::cout;
using std::endl;

class Integer
{
public:
     Integer( int i ) : i_( i ) {}
     operator int() { return i_; }

protected:
     int i_;
};

class Fibonacci : public Integer
{
public:
     Fibonacci( int i );
};

Fibonacci::Fibonacci( int i ) : Integer( i )
{
     try {
          if ( i == 0 || i == 1 ) {
               throw Integer( i );
          } else {
               throw Integer( Fibonacci( i - 1 ) + Fibonacci( i - 2 ) );
          }
     } catch ( Integer ex ) {
          i_ = ex;
     }
}

int main()
{
     const int UNTIL = 20;
     for ( int loop = 0; loop < UNTIL; ++loop ) {
          Fibonacci fibo( loop );
          cout << fibo << ' ';
     }
     cout << endl;
     return 0;
}

Name: Anonymous 2011-11-02 19:06

>>1
so what's the run time?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List