J'ai un petit problème. La source 1:
#include <iostream>
using namespace std;
class my_error {
int e;
public:
my_error (int le) {
e = le;
}
void print ()
{ cout << "ERROR : " << e << endl; }
};
extern "C" void error_throw (int e);
extern "C" void cplusplus_error_handler (int e)
{
throw my_error (e);
}
int main ()
{
cout << "TRY1\n";
try {
throw my_error (2);
} catch (my_error error) {
error.print ();
}
cout << "TRY2\n";
try {
cplusplus_error_handler (2);
} catch (my_error error) {
error.print ();
}
cout << "TRY3\n";
try {
error_throw (2);
} catch (my_error error) {
error.print ();
}
return 0;
}
Compilé avec : g++ t1.cc -Wall -W -pedantic -ansi -c
sans warning.
La source 2:
extern void cplusplus_error_handler (int e);
void error_throw (int e)
{
cplusplus_error_handler (e);
}
Compilé avec : gcc t2.c -Wall -W -pedantic -ansi -c
sans warning.
Mon troisième lié avec : g++ t1.o t2.o
Et mon tout est un a.out qui exécuté donne :
TRY1
ERROR : 2
TRY2
ERROR : 2
TRY3
terminate called after throwing an instance of 'my_error'
Aborted
Question: pourquoi le TRY3 échoue ? Je ne comprends pas !
(GCC et G++ 4.0.2)