It is said here that it’s because of exception specification. I do not understand it. Does this question have any relationship with exception specification?
It is said here that it’s because of exception specification. I do not understand
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
After reading through the tutorial I was a little confused myself by the wording. But I believe it’s as simple as this: the tutorial was explaining why the allocator’s template header shows
allocator(const allocator&) throw();and
template <class U> allocator(const allocator<U>&) throw();even though the copy constructor is fairly useless for an allocator. And the answer was that the specification of an allocator does not allow the constructor to throw exceptions. Therefore the copy constructor public interface defines copy constructors with an exception specification of
throw()(does not throw any exceptions) to prevent someone deriving their own allocator with copy constructors which might throw an exception.See this link for a good description of what an exception specification is if that’s what was throwing you. (No pun intended. Really.)
So, they didn’t mean that when creating an allocator, you have to provide a copy constructor. They just were pointing out that the specification specifically prohibits you from defining one that throws any exceptions.
`