Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward declare in nested namespace

Tags:

c++

c++11

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).

like image 980
Bathsheba Avatar asked Jan 07 '14 09:01

Bathsheba


1 Answers

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.

like image 117
Angew is no longer proud of SO Avatar answered Sep 22 '22 20:09

Angew is no longer proud of SO