23-11-2010, 00:46
|
|
|
|
חבר מתאריך: 04.11.04
הודעות: 6,986
|
|
בעיה "מוזרה" בקומפילציה ב-c++
יש לי את הקוד הבא:
קוד:
#ifndef __EXCEPTION_H_
#define __EXCEPTION_H_
#include <exception>
#include <iostream>
//#include <typeinfo>
using namespace std;
class TreeException : public std::exception {};
class failure : public TreeException {};
class invalidInput : public TreeException {};
template<class result>
class exceptionHandler {
private:
result _failure;
result _badAlloc;
result _invalidInput;
public:
exceptionHandler (result failure,result badAlloc,result invalidInput):
_failure(failure),_badAlloc(badAlloc),_invalidInpu t(invalidInput){}
result operator ()(std::exception &e) {
try {throw ;}
catch (const failure&) {return _failure;}
catch (const bad_alloc&) {return _bad_alloc;}
//catch (const invalidInput&) {return _invalidInput;}
catch (const invalidInput&) {return _invalidInput;}
/*if (typeid(e)==typeid(failure)){return _failure;}
if (typeid(e)==typeid(bad_alloc)){return _badAlloc;}
if (typeid(e)==typeid(invalidInput)){return _invalidInput;}*/
}
};
#endif // __EXCEPTION_H_
משום מה שאני מנסה לקמפל אני מקבל:
קוד:
In member function 'result exceptionHandler<result>::operator()(std::exception&)':|error: '_bad_alloc' was not declared in this scope|
ניסיתי כל מני וריאציות (למחוק את הnamespace ולהוסיף ידנית את ההגדרה, את השטות עם ה typeid וכו'), ובכל פעם אני מקבל את אותה השגיאה המעצבנת הזאת...
הקטע המוזר שיש לי קטע קוד ממש דומה, בתכנית אחרת שפועל בסדר גמור, אז מה אני מפספס?
|