+ 2

what do the words "noexcept, explicit, override" mean?

#define LOVE noexcept #define DEATH explicit #define BEAUTY override

7th Apr 2019, 9:05 AM
Alireza Abbasi
Alireza Abbasi - avatar
3 ответов
+ 7
"noexcept" keyword denotes that a function won't propagate exceptions. If an exception is thrown, the exception won´t propagate to caller functions and program aborts in that function. Example: void fun2() { throw 1; } void fun1() noexcept {   // if fun2 throws an exception // program aborts here   fun2(); } "override" keyword in C++ is used in a similar way that @Override in java. It means that the funcion is overriding a virtual funcion. If there isn't a virtual funcion with that name it will generate an error. This is useful for avoiding typos. Example: class A {   virtual void foo()=0; }; class B : A {  // tried to override virtual foo function in base class A. Typo fooo instead of foo will generate an error due to override keyword    void fooo() override {} }; "explicit" keyword avoid object implicit initialization of classes with one parameter in order to avoid typos. Example: class A { public:   int data;   A(int i) { data = i; } }; // Not allowed A a ={ 3 }; // Must be A a(3);
7th Apr 2019, 12:48 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 8
Ops ! sorry. This is the corrected example: Explicit avoid object implicit initialization of classes with one parameter in order to avoid typos. Example: class A { public:   int data;   explicit A(int i) { data = i; } }; // Not allowed A a ={ 3 }; // Must be A a(3);
7th Apr 2019, 1:28 PM
Javier Felipe Toribio
Javier Felipe Toribio - avatar
+ 2
thanks guy. your explain is very good but you didn't use from explicit keyword in your example.
7th Apr 2019, 1:15 PM
Alireza Abbasi
Alireza Abbasi - avatar