01 // Verlassen einer Methode mit longjmp
02 // Datei: ratjmp.cpp
04 #include <stdio.h>
05 #include <setjmp.h>
07 class ratio
08 {
09 int n;
10 int z;
11 public:
12 ratio () { z=0,n=1;}
13 ratio (int zz, int nn) { z = zz, n = nn;}
14 ~ratio() { printf ("\nDestruktor\n");}
15 ratio add (const ratio &r);
16 void print () { printf ("\nZ: %d, N: %d",z,n);}
17 };
19 // Globale Variable
20 jmp_buf jmpbuf;
22 ratio ratio::add (const ratio &r)
23 {
24 ratio hilf;
25 hilf.n = n*r.n;
26 hilf.z = z*r.n +r.z*n;
27 longjmp (jmpbuf,3); // hilf ohne Destruktor !
28 return hilf;
29 }
31 int main ()
32 {
33 printf ("\x1b[H\x1b[2J"); // Bildschirm löschen
34 ratio r1 (1,2);
35 ratio r2;
37 if (setjmp (jmpbuf)==0)
38   printf ("\nWiederaufsetz- Punkt definiert\n");
39 else
40   {
4