Do invocations of std
constructors need to be qualified with std::
?
class whatever : public std::runtime_error
{
public:
explicit whatever(const std::string& what) : runtime_error(what) {}
}; // ^ do I need std:: here?
It works on my compiler without the qualification, but I'm not sure whether that behavior is standard.
No you don't. The names in the initializer list are looked up in the scope of the whatever
class. This class scope includes names declared in base classes and the name of the base class (runtime_error
) is inserted into the scope of std::runtime_error
(this is standard behaviour for all classes).
Note that this doesn't work if the name that you use is a typedef
for the actual class name. You can easily be tempted with, e.g., std::istream
and friends. See here.
There is no need for the qualification in the initializer list (to be honest I don't know if the qualification is even allowed there), as it is a base and will be found by lookup through the class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With