virtual const char* what() const throw()
{
}
AFAIK it's a function that will return a constant pointer to a mutable char. The rest I am not sure. Could anybody help?
A function consist of two parts: Declaration: the function's name, return type, and parameters (if any) Definition: the body of the function (code to be executed)
For example, if the my_function() function, discussed in the previous section, requires two integer parameters, the declaration could be expressed as follows: return_type my_function(int x, y); where int x, y indicates that the function requires two parameters, both of which are integers.
A declaration means (in C) that you are telling the compiler about type, size and in case of function declaration, type and size of its parameters of any variable, or user-defined type or function in your program. No space is reserved in memory for any variable in case of the declaration.
Actually, it is not required that a function be declared before use in C. If it encounters an attempt to call a function, the compiler will assume a variable argument list and that the function returns int.
Regarding the const throw()
part:
const
means that this function (which is a member function) will not change the observable state of the object it is called on. The compiler enforces this by not allowing you to call non-const
methods from this one, and by not allowing you to modify the values of members.throw()
means that you promise to the compiler that this function will never allow an exception to be emitted. This is called an exception specification, and (long story short) is useless and possibly misleading.From left to right:
virtual
- this function may be overridden in derived classesconst char*
- this function returns a modifiable pointer to a constant (array of) charwhat()
- this function takes no parametersconst
- this function does not modify the (non-mutable
) members of the object on which it is called, and hence can be called on const
instances of its classthrow()
- this function is not expected to throw any exceptions. If it does, unexpected
will be called.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With