Firstly, what is the point of "new"? "new" is a reserved keyword. And new throws a bad_alloc exception by default. What more could he possibly be doing? |
http://en.cppreference.com/w/cpp/header/new
While
new
is a keyword, the
operator new
implementations are actually defined in that header. They are just implicitly included even if you do not explicitly include the header.
(See some notes in
http://en.cppreference.com/w/cpp/memory/new/operator_new , for example. This is actually news to me, pun semi-intended.)
It seems more likely to me that your student was making use of an
std::bad_alloc
exception, which is also defined in that header.
Second, using std::cout? Is that even valid? It's funny because this particular student doesn't even appear to be using the iostream in the file. |
It is absolutely valid, but is unnecessary if
cout
isn't actually used. It allows you to specifically pull in only
cout
from the
std
namespace rather than having to pull in everything with
using namespace std;
if you want to avoid have to type the
std::
prefix.
Are both #include <new> and using std::cout valid? |
You could test this by compiling the code, if you wanted.
Was it smart on his end to do this? |
If your student was using something in each of those header files, then it would be required. Otherwise, it is at worst unnecessary.