c++ - namespace called 'exception' leads to compile problems -
i have problem namespace called "exception"
let's consider following example header:
#include <exception> namespace exception { struct myexception : public std::exception {}; } struct anotherexception : public exception::myexception { anotherexception() : exception::myexception() { } }; this header not compile following error:
namespacetest.hpp: in constructor 'anotherexception::anotherexception()': namespacetest.hpp:12:48: error: expected class-name before '(' token namespacetest.hpp:12:48: error: expected '{' before '(' token there 2 solutions this:
1) qualify namespace "::" in line 12
anotherexception() : ::exception::myexception() { } 2) rename namespace e.g. "exceptional"
what reason, namespace "exceptions" leads confusion? know there class std::exception. cause trouble?
i know there class
std::exception. cause trouble?
yes. within std::exception, unqualified name exception injected class name. inherited so, within class, unqualified exception refers that, not namespace.
Comments
Post a Comment