I can not seem to get my try/catch block to work.
I am trying to use it in a templated class and I keep getting parse errors.
Is my syntax correct?
I have also tried
Which also gives me parse errors.Code:template<class T> catch(Test<T>::whoops) // <--- This is giving me a parse error { cout<< " it works " << endl << endl; system("pause"); }
Any pointers would be appreciated.
Thank you,Code:#include <iostream> #include <iomanip> #include <string> using namespace std; template<class T> class Test { private: T balance; public: class whoops {}; void withdraw(float temp); void see(); void SetBalance(); }; int main() { Test<float> data[10]; float try_; int exit = 0; char select = '\0'; data[0].SetBalance(); do { cout<< "(1/2) ->: "; cin>> select; switch(select) { case '1': cout<< "hmm: "; cin>> try_; try { data[0].withdraw(try_); } catch(Test::whoops) // <--- This is giving me a parse error { cout<< " it works " << endl << endl; system("pause"); } break; case '2': data[0].see(); break; default: cout<< "try again" << endl << endl; break; } }while(exit == 0); return 0; } template<class T> void Test<T>::withdraw(float temp) { cout<< balance << endl; if(temp>balance) throw whoops(); balance-=temp; } template<class T> void TestTT>::SetBalance() { balance = 100; } template<class T> void Test<T>::see() { cout<< balance; }
Rich



LinkBack URL
About LinkBacks


