Bonjour,
Je suis en train d'apprendre les exceptions et j'ai une erreur, je ne comprends pas pourquoi.
Voici mon code:
// A simple exception-handling example that checks for
// divide-by-zero exceptions.
#include <iostream>
using namespace std;
#include <exception>
using std::exception;
// DivideByZeroException objects should be thrown by functions
// upon detecting division-by-zero exceptions
class DivideByZeroException : public exception {
public:
// constructor specifies default error message
DivideByZeroException::DivideByZeroException() : exception( "attempted to divide by zero" ) {}
}; // end class
// perform division and throw DivideByZeroException object if
// divide-by-zero exception occurs
double quotient( int numerator, int denominator )
{
if ( denominator == 0 )
throw DivideByZeroException(); // terminate function
return numerator / denominator;
}
int main()
{
int number1; // user-specified numerator
int number2; // user-specified denominator
double result; // result of division
cout << "Enter two integers";
// enable user to enter two integers to divide
cin >> number1 >> number2;
// try block contains code that might throw exception
// and code that should not execute if an exception occurs
try {
result = quotient( number1, number2 );
cout << "The quotient is: " << result << endl;
}
catch ( DivideByZeroException ÷ByZeroException ) {
cout << "Exception occurred: " <<
divideByZeroException.what() << endl;
}
cout << endl;
return 0; /
}
Lorsque je compile, voici l'erreur que j'ai :
[serial@localhost exception2]$ g++ *.cpp -o exception2
main.cpp:14: error: extra qualification 'DivideByZeroException::' on member 'DivideByZeroException'
main.cpp: In constructor 'DivideByZeroException::DivideByZeroException()':
main.cpp:14: error: no matching function for call to 'std::exception::exception(const char [28])'
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/exception:57: note: candidates are: std::exception::exception()
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/exception:55: note: std::exception::exception(const std::exception&)
Merci de votre aide.

-----------------------------------------------------------------------------------
http://www.mesdevoirs.net -- Corrections de devoirs de mathématiques en ligne