diff --git a/teoria/exceptions.cpp b/teoria/exceptions.cpp new file mode 100644 index 0000000..0f4cf7f --- /dev/null +++ b/teoria/exceptions.cpp @@ -0,0 +1,93 @@ +#include +using namespace std; + +void exceptions(); +void noExceptFun() noexcept; +void nestedTryCatch(); + +int main(){ + exceptions(); + nestedTryCatch(); + try{ + noExceptFun(); + }catch(bad_alloc ex){ + cout<<"Questo punto non verrà mai raggiunto"; + } +} + +void nestedTryCatch(){ + try{ + try{ + throw exception(); + }catch(exception ex){ + throw ex; + } + }catch(exception ex){ + cout<<"Eccezione catturata"< +#include // Solo per puntatori alla C++ + +using namespace std; + +int func(int a); +void C_like_functionPointer(); +void C_like_typedef_functionPointer(); +void CPP_like_functionPointer(); +void CPP_like_typedef_functionPointer(); + +int main(){ + C_like_functionPointer(); + C_like_typedef_functionPointer(); + CPP_like_functionPointer(); + CPP_like_typedef_functionPointer(); + return 0; +} + +int func(int a){ + return 2*a; +} + +void CPP_like_typedef_functionPointer(){ + // funptrType è un nuovo tipo che definisce puntatori a funzione di tipo int f(int) + typedef function funptrType; + funptrType ptr = func; + cout< funptr = nullptr; + funptr = &func; + funptr = func; + cout< +#include + +#include // Per implementazione alla C [sconsigliato] +#include // Per implementazione alla C [sconsigliato] + +using namespace std; + +void C_like_randomNumbers(); +void Cpp_like_randomNumbers(); +int main(){ + Cpp_like_randomNumbers(); + return 0; +} + +void Cpp_like_randomNumbers(){ + default_random_engine gen(random_device{}()); + uniform_int_distribution dist(0,100); + for(int i=1;i<=15;i++){ + cout< // include anche +using namespace std; + +int main(){ + string s1 = "Alan"; + string s2 = {"Turing"}; + string s3{"Kurt"}; + string s4("Godel"); + + string stringa_concatenata = s1 + s3; // l'operatore + è stato overloaded per le stringhe + cout<>input_string; // se si inserisce "Alan Turing" verrà preso solo "Alan" + cout<