class Person{ public: Person(){ mAge = 0; } void setAge(int age){ if(age < 0 || age > 100){ throw out_of_range("年齡應該在0-100之間!"); } this->mAge = age; } public: int mAge; }; void test01(){ Person p; try{ p.setAge(1024); }catch(out_of_range& e){//此處報錯 cout << e.what() << endl; } }
gcc編譯報錯catching polymorphic type 'class std::exception' by value [-Wcatch-value=];