Original Post
Is there any way of twisting the language to allow a nested class to derive from the class it it nested in? Sounds hideous, but here's the example I'm thinking of: The idea is that the heirarchy is directly visible in the identifier names. The exception handling code would like to know that exceptions thrown by members of Task came from there (perhaps for logging purposes), it'd like to know whether the exception was the object failing to initialise (so it can log the problem, and step around it or terminate depending on whether we're debugging or not), but it'd be nice to express the heirarchy in the language itself. Task::Except is very clear what kind of Except it is. Task::Except::OpFailed also makes sense. Task::OpFailed, though, is ambiguous. Anyway, the obvious reson why this isn't working is that Task::Except is incomplete where OpFailed and BadInit try to derive from it, so it generates a compiler error. Is there any way to circumvent this (perhaps with forward declarations of classes)?
class Task
{
public:
class Except : public std::runtime_error
{
public:
class BadInit : public Except
{
//...
};
class OpFailed : public Except
{
//...
};
};
void Init() throw(BadInit);
void DoStuff() throw(BadInit, OpFailed);
void DeInit() throw(BadInit);
};