2nd edition of A Tour of C++ of Bjarne's Stroustrup goes into templates in chapter 6.
This is the code on page 80 that I am uncertain about. There is a Negative_size exception but I haven't been able to find it with a google search and adding std:: to it gave me the error:
error: ‘Negative_size’ is not a member of ‘std’
26 | throw std::Negative_size{};
template <typename T>
class Vector
{
public:
explicit Vector(int s);
~Vector()
{
delete[] elem;
}
T &operator[](int i);
const T &operator[](int i) const; // for const Vectors
int size() const
{
return sz;
}
private:
T *elem;
int sz;
};
template <typename T>
Vector<T>::Vector(int s)
{
if (s < 0)
{
throw std::Negative_size{}; // where the compilation error occurs
}
}
I also didn't see it mentioned in the errata.
EDIT:
Responses to comments
- Chapter 6 is about templates.
- I have read the book from the first chapter and so I haven't skipped anything. I wouldn't have posted a question otherwise.
- I initially posted code to figure out what the error is but I am including the rest to reproduce the problem. I didn't want to include extra code that wasn't asking about the issue itself but this was requested.