Hi, I'm creating exception classes for one of my class (say, Foo), and would like to separate (not only the implementation but also) the declaration from the declaration of Foo.
class Foo
{
// ...
// exception classes
class xBar
{
// ...
virtualvoid SomeFunc();
};
class xBarOne : public xBar
{
// ...
};
class xBarTwo : public xBar
{
// ...
};
// ...
};
It's quite a bunch of hierarchies over there, I don't like them appearing to "flood" the interface :\
Is it possible to separate? (actually I got a few more questions)
If yes,
Is it a good idea to do so? Or to put it this way: should the declarations of exception classes be part of the "interface", i.e. the interface for the users?
If no,
can I separate the function definition in another *.cpp like
Making them members of Foo basically implies that these exceptions are specific to Foo and will never
be thrown by anything other than a Foo object.
If you are concerned about polluting the outer namespace (ie, global namespace), then I'd suggest creating
a namespace into which you should place Foo and its exception classes.
To answer your last question, yes, you can, provided that the exception classes are declared public (which
I'm assuming they are).
Ah, sorry, I think I misunderstood you and led you down the wrong path.
You'll have to put the entire declaration of the exception classes in Foo's body.
You can put the implementation of those classes in a separate file provided they
are declared public inside Foo.