Hi,
Check out the following code the declaration and definition. (They are in separate files in the project):
Code:
class stack_size_error : public std::length_error {
public:
explicit stack_size_error(const std::string &msg);
};
stack_size_error::stack_size_error(const std::string &msg) : std::length_error(msg){};
So a user made exception that descends from one in the standard library. Ok. It seems it calls its base class constructor when used and just passes the string argument into that. However if I try and write a custom constructor (which is empty) for it like so:
Code:
stack_size_error::stack_size_error(const std::string &msg) {};
The compiler states that it's not a matching function call. I don't know why though. Surely I can make a derived class and then write my own valid constructor for it? Compiler won't accept it though. I'm aware that when one calls a derived class constructor it also automatically calls its parent constructor. Up to now though I've never had to explicitly state that in code.
I'm wondering does the base class std::length_error perhaps not have a constructor defined that takes no arguments? Maybe that's it.
I'm confused, thanks