In fact, the link is used to avoid an unnecessary copy of the object.
Now, to understand why const used, try the following:
std::string & x= std::string();
This will give a compilation error. This is because the expression std::string() creates a temporary object that cannot be bound to a non-constant reference. However, the temporary can be bound to a const reference, so const is required:
const std::string & x = std::string();
Now back to the constructor in your code:
CMyException (const std::string & Libelle = std::string());
It sets the default value for the parameter. The default value is created from a temporary object. Therefore, you need const (if you use the link).
There is also the advantage of using a const reference: if you have such a constructor, you can throw an exception like this:
throw CMyException("error");
It creates a temporary object of type std::string from the string literal "error" , and this temporary is associated with a const reference.
source share