I'm writing a class (in a header file) that requires the following method:
static const foo::bar::clz* getSomething(void);
As I don't want to pollute the header file with an #include
I choose to forward declare clz
:
namespace foo
{
namespace bar
{
class clz;
}
}
But that's rather clumsy too. Is there a cuter way of doing this in C++11? Something along the lines of
class foo::bar::clz;
It would be nicer still if you didn't have to anticipate whether or not it's implemented as a class
, struct
or union
. Have the C++11 grammarians covered that one too? (typename auto
could be a candidate but I'm not an expert in C++ grammar).
The nested namespaces can't be avoided.
As for class
vs. struct
vs. union
, partially: class
and struct
can be used interchangeably. If it's a union
, it must be declared as such.
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