I want to do the following:
class ErrorBase
{
public:
void SetError(unsigned errorCode)
{
mErrorCode = errorCode;
}
char const* Explanation(unsigned errorCode) const
{
return errorExplanations[errorCode];
}
private:
char const* errorExplanations[];
unsigned mErrorCode;
};
class MyError : virtual public ErrorBase
{
public:
enum ErrorCodes {
eNone,
eGeneric,
eMySpecificError
};
MyError()
{
// I want this to refer to the parent class's attribute,
// such that when Explanation() is executed, it uses this
errorExplanations = {
"no error",
"error in MyClass",
"specific error"
}
}
~MyError() { }
};
But I get the following error on the line declaring errorExplanations
in the child class:
error: expected primary-expression before '{' token
How do I declare errorExplanations
in the child class such that I can instantiate a child, and call myChild.Explanation()
and get one of the error strings defined in the child's constructor?
Any suggestions/corrections regarding my usage of const
, virtual
, public
, etc are appreciated, Thanks!