I’ve a set of classes in my namespace and want to group forward declaration in a define.hpp file.
I’ve already achieve this in others projects, here is an example :
namespace Makefile
{
class Builder;
class Config;
class Options;
class Target;
class Tool;
}
My problem is that — for example — the Config class include the following strongly typed enum :
namespace Makefile
{
class Config
{
public:
enum class OperatingSystem : unsigned int
{
MacOSX = 0,
Linux = 1,
Windows = 2
};
};
}
So I would like to add this enum class in my forward-declaration file, and add the following line :
enum class Config::OperatingSystem : unsigned int;
Here comes my problem, I get the following error when compiling :
src/Makefile/define.hpp:6:13: error: opaque-enum-specifier must use a simple identifier
Does it mean that it is not possible to forward-declare nested type?
Is there any workaround to this problem?
Is this due to my compiler?
My configuration : GCC 4.6.0 on Mac OS X.7
Compilation flags : --std=c++0x -g3 -gdwarf-2 -W -Wall -iquote gen -iquote src
You simply make the opaque enum in the usual place:
And then, wherever you want to define the enum constants:
The error
opaque-enum-specifier must use a simple identifieris there to tell you that if you need to refer to the enum with other than a simple identifier, you are doing it wrong.UPDATE:
For your specific needs, you may simply declare the enum outside of the class, or else in a simple class with only the opaque enum, and inherit
Configfrom it: