<p>I'm trying to do something like the following:</p>

<pre><code>enum E;

void Foo(E e);

enum E {A, B, C};
</code></pre>

<p>which the compiler rejects.  I've had a quick look on Google and the consensus seems to be "you can't do it", but I can't understand why.  Can anyone explain?</p>

<p>Clarification 2: I'm doing this as I have private methods in a class that take said enum, and I do not want the enum's values exposed - so, for example, I do not want anyone to know that E is defined as</p>

<pre><code>enum E {
    FUNCTIONALITY_NORMAL, FUNCTIONALITY_RESTRICTED, FUNCTIONALITY_FOR_PROJECT_X
}
</code></pre>

<p>as project X is not something I want my users to know about.</p>

<p>So, I wanted to forward declare the enum so I could put the private methods in the header file, declare the enum internally in the cpp, and distribute the built library file and header to people.</p>

<p>As for the compiler - it's GCC.</p>

[{'answer_id': 71428, 'author': 'prakash', 'author_id': 123, 'author_profile': 'https://Stackoverflow.com/users/123', 'pm_score': 1, 'selected': False, 'text': '<p>It seems it can not be forward-declared in GCC!</p>\n<p>An interesting discussion is <a href="http://bytes.com/forum/thread62285.html" rel="nofollow noreferrer">here</a>.</p>\n'}, {'answer_id': 71436, 'author': 'Alexey Feldgendler', 'author_id': 10682, 'author_profile': 'https://Stackoverflow.com/users/10682', 'pm_score': 3, 'selected': False, 'text': "<p>There is indeed no such thing as a forward declaration of enum. As an enum's definition doesn't contain any code that could depend on other code using the enum, it's usually not a problem to define the enum completely when you're first declaring it.</p>\n\n<p>If the only use of your enum is by private member functions, you can implement encapsulation by having the enum itself as a private member of that class. The enum still has to be fully defined at the point of declaration, that is, within the class definition. However, this is not a bigger problem as declaring private member functions there, and is not a worse exposal of implementation internals than that.</p>\n\n<p>If you need a deeper degree of concealment for your implementation details, you can break it into an abstract interface, only consisting of pure virtual functions, and a concrete, completely concealed, class implementing (inheriting) the interface. Creation of class instances can be handled by a factory or a static member function of the interface. That way, even the real class name, let alone its private functions, won't be exposed.</p>\n"}, {'answer_id': 71448, 'author': 'Carl Seleborg', 'author_id': 2095, 'author_profile': 'https://Stackoverflow.com/users/2095', 'pm_score': -1, 'selected': False, 'text': "<p>Because the enum can be an integral size of varying size (the compiler decides which size a given enum has), the pointer to the enum can also have varying size, since it's an integral type (chars have pointers of a different size on some platforms for instance).</p>\n\n<p>So the compiler can't even let you forward-declare the enum and user a pointer to it, because even there, it needs the size of the enum.</p>\n"}, {'answer_id': 71495, 'author': 'James Hopkin', 'author_id': 11828, 'author_profile': 'https://Stackoverflow.com/users/11828', 'pm_score': 4, 'selected': False, 'text': "<p>[My answer is wrong, but I've left it here because the comments are useful].</p>\n\n<p>Forward declaring enums is non-standard, because pointers to different enum types are not guaranteed to be the same size. The compiler may need to see the definition to know what size pointers can be used with this type.</p>\n\n<p>In practice, at least on all the popular compilers, pointers to enums are a consistent size. Forward declaration of enums is provided as a language extension by Visual C++, for example.</p>\n"}, {'answer_id': 71961, 'author': 'Laurie Cheers', 'author_id': 12066, 'author_profile': 'https://Stackoverflow.com/users/12066', 'pm_score': 3, 'selected': False, 'text': "<p>I'd do it this way:</p>\n\n<p>[in the public header]</p>\n\n<pre><code>typedef unsigned long E;\n\nvoid Foo(E e);\n</code></pre>\n\n<p>[in the internal header]</p>\n\n<pre><code>enum Econtent { FUNCTIONALITY_NORMAL, FUNCTIONALITY_RESTRICTED, FUNCTIONALITY_FOR_PROJECT_X,\n  FORCE_32BIT = 0xFFFFFFFF };\n</code></pre>\n\n<p>By adding FORCE_32BIT we ensure that Econtent compiles to a long, so it's interchangeable with E.</p>\n"}, {'answer_id': 72599, 'author': 'KJAWolf', 'author_id': 12302, 'author_profile': 'https://Stackoverflow.com/users/12302', 'pm_score': 9, 'selected': True, 'text': '<p>The reason the enum can\'t be forward declared is that, without knowing the values, the compiler can\'t know the storage required for the enum variable.  C++ compilers are allowed to specify the actual storage space based on the size necessary to contain all the values specified.  If all that is visible is the forward declaration, the translation unit can\'t know what storage size has been chosen – it could be a <code>char</code>, or an <code>int</code>, or something else.</p>\n<hr />\n<p>From Section 7.2.5 of the ISO C++ Standard:</p>\n<blockquote>\n<p>The <em>underlying type</em> of an enumeration is an integral type that can represent all the enumerator values defined in the enumeration. It is implementation-defined which integral type is used as the underlying type for an enumeration except that the underlying type shall not be larger than <code>int</code> unless the value of an enumerator cannot fit in an <code>int</code> or <code>unsigned int</code>. If the <em>enumerator-list</em> is empty, the underlying type is as if the enumeration had a single enumerator with value 0. The value of <code>sizeof()</code> applied to an enumeration type, an object of enumeration type, or an enumerator, is the value of <code>sizeof()</code> applied to the underlying type.</p>\n</blockquote>\n<p>Since the <em>caller</em> to the function must know the sizes of the parameters to correctly set up the call stack, the number of enumerations in an enumeration list must be known before the function prototype.</p>\n<p>Update:</p>\n<p>In C++0X, a syntax for forward declaring enum types has been proposed and accepted.  You can see the proposal at <em><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2764.pdf" rel="nofollow noreferrer">Forward declaration of enumerations (rev.3)</a></em></p>\n'}, {'answer_id': 78426, 'author': 'paercebal', 'author_id': 14089, 'author_profile': 'https://Stackoverflow.com/users/14089', 'pm_score': 0, 'selected': False, 'text': "<p>My solution to your problem would be to either:</p>\n\n<p>1 - use int instead of enums: Declare your ints in an anonymous namespace in your CPP file (not in the header):</p>\n\n<pre><code>namespace\n{\n   const int FUNCTIONALITY_NORMAL = 0 ;\n   const int FUNCTIONALITY_RESTRICTED = 1 ;\n   const int FUNCTIONALITY_FOR_PROJECT_X = 2 ;\n}\n</code></pre>\n\n<p>As your methods are private, no one will mess with the data. You could even go further to test if someone sends you an invalid data:</p>\n\n<pre><code>namespace\n{\n   const int FUNCTIONALITY_begin = 0 ;\n   const int FUNCTIONALITY_NORMAL = 0 ;\n   const int FUNCTIONALITY_RESTRICTED = 1 ;\n   const int FUNCTIONALITY_FOR_PROJECT_X = 2 ;\n   const int FUNCTIONALITY_end = 3 ;\n\n   bool isFunctionalityCorrect(int i)\n   {\n      return (i &gt;= FUNCTIONALITY_begin) &amp;&amp; (i &lt; FUNCTIONALITY_end) ;\n   }\n}\n</code></pre>\n\n<p>2 : create a full class with limited const instantiations, like done in Java. Forward declare the class, and then define it in the CPP file, and instanciate only the enum-like values. I did something like that in C++, and the result was not as satisfying as desired, as it needed some code to simulate an enum (copy construction, operator =, etc.).</p>\n\n<p>3 : As proposed before, use the privately declared enum. Despite the fact an user will see its full definition, it won't be able to use it, nor use the private methods. So you'll usually be able to modify the enum and the content of the existing methods without needing recompiling of code using your class.</p>\n\n<p>My guess would be either the solution 3 or 1.</p>\n"}, {'answer_id': 78448, 'author': 'Vincent Robert', 'author_id': 268, 'author_profile': 'https://Stackoverflow.com/users/268', 'pm_score': 2, 'selected': False, 'text': '<p>If you really don\'t want your enum to appear in your header file <em>and</em> ensure that it is only used by private methods, then one solution can be to go with the <a href="https://cpppatterns.com/patterns/pimpl.html" rel="nofollow noreferrer">PIMPL</a> principle.</p>\n<p>It\'s a technique that ensure to hide the class internals in the headers by just declaring:</p>\n<pre><code>class A\n{\npublic:\n    ...\nprivate:\n    void* pImpl;\n};\n</code></pre>\n<p>Then in your implementation file (.cpp), you declare a class that will be the representation of the internals.</p>\n<pre><code>class AImpl\n{\npublic:\n    AImpl(A* pThis): m_pThis(pThis) {}\n\n    ... all private methods here ...\nprivate:\n    A* m_pThis;\n};\n</code></pre>\n<p>You must dynamically create the implementation in the class constructor and delete it in the destructor and when implementing public method, you must use:</p>\n<pre><code>((AImpl*)pImpl)-&gt;PrivateMethod();\n</code></pre>\n<p>There are pros for using PIMPL. One is that it decouples your class header from its implementation, and there isn\'t any need to recompile other classes when changing one class implementation. Another is that is speeds up your compilation time, because your headers are so simple.</p>\n<p>But it\'s a pain to use, so you should really ask yourself if just declaring your enum as private in the header is that much a trouble.</p>\n'}, {'answer_id': 483320, 'author': 'xtofl', 'author_id': 6610, 'author_profile': 'https://Stackoverflow.com/users/6610', 'pm_score': -1, 'selected': False, 'text': "<p>You define an enumeration to restrict the possible values of elements of the type to a limited set.  This restriction is to be enforced at compile time.</p>\n\n<p>When forward declaring the fact that you will use a 'limited set' later on doesn't add any value: subsequent code needs to know the possible values in order to benefit from it.</p>\n\n<p>Although the compiler <em>is</em> concerned about the size of the enumerated type, the <em>intent</em> of the enumeration gets lost when you forward declare it.</p>\n"}, {'answer_id': 685239, 'author': 'Dan Olson', 'author_id': 69283, 'author_profile': 'https://Stackoverflow.com/users/69283', 'pm_score': 2, 'selected': False, 'text': "<p>There's some dissent since this got bumped (sort of), so here's some relevant bits from the standard.  Research shows that the standard doesn't really define forward declaration, nor does it explicitly state that enums can or can't be forward declared.</p>\n<p>First, from dcl.enum, section 7.2:</p>\n<blockquote>\n<p>The underlying type of an enumeration\nis an integral type that can represent\nall the enumerator values defined in\nthe enumeration. It is\nimplementation-defined which integral\ntype is used as the underlying type\nfor an enumeration except that the\nunderlying type shall not be larger\nthan int unless the value of an\nenumerator cannot fit in an int or\nunsigned int. If the enumerator-list\nis empty, the underlying type is as if\nthe enumeration had a single\nenumerator with value 0. The value of\nsizeof() applied to an enumeration\ntype, an object of enumeration type,\nor an enumerator, is the value of\nsizeof() applied to the underlying\ntype.</p>\n</blockquote>\n<p>So the underlying type of an enum is implementation-defined, with one minor restriction.</p>\n<p>Next we flip to the section on &quot;incomplete types&quot; (3.9), which is about as close as we come to any standard on forward declarations:</p>\n<blockquote>\n<p>A class that has been declared but not defined, or an array of unknown size or of\nincomplete element type, is an incompletely-defined object type.</p>\n<p>A class type (such as &quot;class X&quot;) might be incomplete at one point in a translation\nunit and complete later on; the type &quot;class X&quot; is the same type at both points. The\ndeclared type of an array object might be an array of incomplete class type and\ntherefore incomplete; if the class type is completed later on in the translation unit,\nthe array type becomes complete; the array type at those two points is the same type.\nThe declared type of an array object might be an array of unknown size and therefore be\nincomplete at one point in a translation unit and complete later on; the array types at\nthose two points (&quot;array of unknown bound of T&quot; and &quot;array of N T&quot;) are different\ntypes. The type of a pointer to array of unknown size, or of a type defined by a typedef\ndeclaration to be an array of unknown size, cannot be completed.</p>\n</blockquote>\n<p>So there, the standard pretty much laid out the types that can be forward declared.  Enum wasn't there, so compiler authors generally regard forward declaring as disallowed by the standard due to the variable size of its underlying type.</p>\n<p>It makes sense, too.  Enums are usually referenced in by-value situations, and the compiler would indeed need to know the storage size in those situations.  Since the storage size is implementation defined, many compilers may just choose to use 32 bit values for the underlying type of every enum, at which point it becomes possible to forward declare them.</p>\n<p>An interesting experiment might be to try forward declaring an enum in Visual\xa0Studio, then forcing it to use an underlying type greater than sizeof(int) as explained above to see what happens.</p>\n"}, {'answer_id': 686303, 'author': 'Johannes Schaub - litb', 'author_id': 34509, 'author_profile': 'https://Stackoverflow.com/users/34509', 'pm_score': 3, 'selected': False, 'text': "<p>I am just noting that the reason actually <em>is</em> that the size of the enum is not yet known after forward declaration. Well, you use forward declaration of a struct to be able to pass a pointer around or refer to an object from a place that's referred to in the forward declared struct definition itself too.</p>\n<p>Forward declaring an enum would not be too useful, because one would wish to be able to pass around the enum by-value. You couldn't even have a pointer to it, because I recently got told some platforms use pointers of different size for <em>char</em> than for <em>int</em> or <em>long</em>. So it all depends on the content of the enum.</p>\n<p>The current C++ Standard explicitly disallows doing something like</p>\n<pre><code>enum X;\n</code></pre>\n<p>(in <code>7.1.5.3/1</code>). But the next C++ Standard due to next year allows the following, which convinced me the problem actually <em>has</em> to do with the underlying type:</p>\n<pre><code>enum X : int;\n</code></pre>\n<p>It's known as an &quot;opaque&quot; enum declaration. You can even use X <em>by value</em> in the following code. And its enumerators can later be defined in a later redeclaration of the enumeration. See <code>7.2</code> in the current working draft.</p>\n"}, {'answer_id': 717633, 'author': 'zhaorufei', 'author_id': 64469, 'author_profile': 'https://Stackoverflow.com/users/64469', 'pm_score': 1, 'selected': False, 'text': '<p>For <a href="https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B" rel="nofollow noreferrer">VC++</a>, here\'s the test about forward declaration and specifying the underlying type:</p>\n<ol>\n<li>The following code is compiled OK.</li>\n</ol>\n<pre>\n    typedef int myint;\n    enum T ;\n    void foo(T * tp )\n    {\n        * tp = (T)0x12345678;\n    }\n    enum T : char\n    {\n        A\n    };\n</pre>\n<p>But I got the warning for <code>/W4</code> (<code>/W3</code> does not incur this warning)</p>\n<blockquote>\n<p>warning C4480: nonstandard extension used: specifying underlying type for enum \'T\'</p>\n</blockquote>\n<ol start="2">\n<li>VC++ (Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86) looks buggy in the above case:</li>\n</ol>\n<ul>\n<li>when seeing enum T; VC assumes the enum type T uses default 4 bytes int as underlying type, so the generated assembly code is:</li>\n</ul>\n<pre>\n    ?foo@@YAXPAW4T@@@Z PROC                    ; foo\n    ; File e:\\work\\c_cpp\\cpp_snippet.cpp\n    ; Line 13\n        push    ebp\n        mov    ebp, esp\n    ; Line 14\n        mov    eax, DWORD PTR _tp$[ebp]\n        mov    DWORD PTR [eax], 305419896        ; 12345678H\n    ; Line 15\n        pop    ebp\n        ret    0\n    ?foo@@YAXPAW4T@@@Z ENDP                    ; foo\n</pre>\n<p>The above assembly code is extracted from /Fatest.asm directly, not my personal guess.</p>\n<p>Do you see the</p>\n<pre><code>mov DWORD PTR[eax], 305419896        ; 12345678H\n</code></pre>\n<p>line?</p>\n<p>the following code snippet proves it:</p>\n<pre>\n    int main(int argc, char *argv)\n    {\n        union {\n            char ca[4];\n            T t;\n        }a;\n        a.ca[0] = a.ca[1] = a.[ca[2] = a.ca[3] = 1;\n        foo( &a.t) ;\n        printf("%#x, %#x, %#x, %#x\\n",  a.ca[0], a.ca[1], a.ca[2], a.ca[3] );\n        return 0;\n    }\n</pre>\n<p>The result is:</p>\n<p>0x78, 0x56, 0x34, 0x12</p>\n<ul>\n<li>After removing the forward declaration of enum T and move the definition of function foo after the enum T\'s definition: the result is OK:</li>\n</ul>\n<p>The above key instruction becomes:</p>\n<p>mov    BYTE PTR [eax], 120            ; 00000078H</p>\n<p>The final result is:</p>\n<p>0x78, 0x1, 0x1, 0x1</p>\n<p>Note the value is not being overwritten.</p>\n<p>So using of the forward-declaration of enum in VC++ is considered harmful.</p>\n<p>BTW, to not surprise, the syntax for declaration of the underlying type is same as its in C#. In pratice I found it\'s worth to save three bytes by specifying the underlying type as char when talking to the embedded system, which is memory limited.</p>\n'}, {'answer_id': 990983, 'author': 'mavam', 'author_id': 1170277, 'author_profile': 'https://Stackoverflow.com/users/1170277', 'pm_score': 1, 'selected': False, 'text': '<p>In my projects, I adopted the <a href="http://www.ddj.com/cpp/184403894" rel="nofollow noreferrer">Namespace-Bound Enumeration</a> technique to deal with <code>enum</code>s from legacy and 3rd-party components. Here is an example:</p>\n\n<h3>forward.h:</h3>\n\n<pre><code>namespace type\n{\n    class legacy_type;\n    typedef const legacy_type&amp; type;\n}\n</code></pre>\n\n<h3>enum.h:</h3>\n\n<pre><code>// May be defined here or pulled in via #include.\nnamespace legacy\n{\n    enum evil { x , y, z };\n}\n\n\nnamespace type\n{\n    using legacy::evil;\n\n    class legacy_type\n    {\n    public:\n        legacy_type(evil e)\n            : e_(e)\n        {}\n\n        operator evil() const\n        {\n            return e_;\n        }\n\n    private:\n        evil e_;\n    };\n}\n</code></pre>\n\n<h3>foo.h:</h3>\n\n<pre><code>#include "forward.h"\n\nclass foo\n{\npublic:\n    void f(type::type t);\n};\n</code></pre>\n\n<h3>foo.cc:</h3>\n\n<pre><code>#include "foo.h"\n\n#include &lt;iostream&gt;\n#include "enum.h"\n\nvoid foo::f(type::type t)\n{\n    switch (t)\n    {\n        case legacy::x:\n            std::cout &lt;&lt; "x" &lt;&lt; std::endl;\n            break;\n        case legacy::y:\n            std::cout &lt;&lt; "y" &lt;&lt; std::endl;\n            break;\n        case legacy::z:\n            std::cout &lt;&lt; "z" &lt;&lt; std::endl;\n            break;\n        default:\n            std::cout &lt;&lt; "default" &lt;&lt; std::endl;\n    }\n}\n</code></pre>\n\n<h3>main.cc:</h3>\n\n<pre><code>#include "foo.h"\n#include "enum.h"\n\nint main()\n{\n    foo fu;\n    fu.f(legacy::x);\n\n    return 0;\n}\n</code></pre>\n\n<p>Note that the <code>foo.h</code> header does not have to know anything about <code>legacy::evil</code>. Only the files that use the legacy type <code>legacy::evil</code> (here: main.cc) need to include <code>enum.h</code>.</p>\n'}, {'answer_id': 1280969, 'author': 'user119017', 'author_id': 119017, 'author_profile': 'https://Stackoverflow.com/users/119017', 'pm_score': 8, 'selected': False, 'text': "<p>Forward declaration of enums is possible since C++11. Previously, the reason enum types couldn't be forward declared was because the size of the enumeration depended on its contents. As long as the size of the enumeration is specified by the application, it can be forward declared:</p>\n<pre><code>enum Enum1;                     // Illegal in C++03 and C++11; no size is explicitly specified.\nenum Enum2 : unsigned int;      // Legal in C++11.\nenum class Enum3;               // Legal in C++11, because enum class declarations have a default type of &quot;int&quot;.\nenum class Enum4: unsigned int; // Legal C++11.\nenum Enum2 : unsigned short;    // Illegal in C++11, because Enum2 was previously declared with a different type.\n</code></pre>\n"}, {'answer_id': 1932119, 'author': 'Brian R. Bondy', 'author_id': 3153, 'author_profile': 'https://Stackoverflow.com/users/3153', 'pm_score': 5, 'selected': False, 'text': '<p>Forward declaring things in C++ is very useful because it <a href="http://brianbondy.com/blog/id/5/slow-compilation-time" rel="nofollow noreferrer">dramatically speeds up compilation time</a>.  You can forward declare several things in C++ including: <code>struct</code>, <code>class</code>, <code>function</code>, etc...</p>\n<p>But can you forward declare an <code>enum</code> in C++?</p>\n<p>No, you can\'t.</p>\n<p>But why not allow it?  If it were allowed you could define your <code>enum</code> type in your header file, and your <code>enum</code> values in your source file.  It sounds like it should be allowed, right?</p>\n<p>Wrong.</p>\n<p>In C++ there is no default type for <code>enum</code> like there is in C# (int).  In C++ your <code>enum</code> type will be determined by the compiler to be any type that will fit the range of values you have for your <code>enum</code>.</p>\n<p>What does that mean?</p>\n<p>It means that your <code>enum</code>\'s underlying type cannot be fully determined until you have all of the values of the <code>enum</code> defined. Which means you cannot separate the declaration and definition of your <code>enum</code>.  And therefore you cannot forward declare an <code>enum</code> in C++.</p>\n<p>The ISO C++ standard S7.2.5:</p>\n<blockquote>\n<p>The underlying type of an enumeration is an integral type that can represent all the enumerator values defined in the enumeration. It is implementation-defined which integral type is used as the underlying type for an enumeration except that the underlying type shall not be larger than <code>int</code> unless the value of an enumerator cannot fit in an <code>int</code> or <code>unsigned int</code>. If the enumerator-list is empty, the underlying type is as if the enumeration had a single enumerator with value 0. The value of <code>sizeof()</code> applied to an enumeration type, an object of enumeration type, or an enumerator, is the value of <code>sizeof()</code> applied to the underlying type.</p>\n</blockquote>\n<p>You can determine the size of an enumerated type in C++ by using the <code>sizeof</code> operator.  The size of the enumerated type is the size of its underlying type.   In this way you can guess which type your compiler is using for your <code>enum</code>.</p>\n<p>What if you specify the type of your <code>enum</code> explicitly like this:</p>\n<pre><code>enum Color : char { Red=0, Green=1, Blue=2};\nassert(sizeof Color == 1);\n</code></pre>\n<p>Can you then forward declare your <code>enum</code>?</p>\n<p>No.  But why not?</p>\n<p>Specifying the type of an <code>enum</code> is not actually part of the current C++ standard.  It is a VC++ extension.   It will be part of C++0x though.</p>\n<p><a href="http://brianbondy.com/blog/id/93/forward-declaring-enums-in-c" rel="nofollow noreferrer">Source</a></p>\n'}, {'answer_id': 11382046, 'author': 'Leszek Swirski', 'author_id': 1509804, 'author_profile': 'https://Stackoverflow.com/users/1509804', 'pm_score': 2, 'selected': False, 'text': '<p>You can wrap the enum in a struct, adding in some constructors and type conversions, and forward declare the struct instead.</p>\n\n<pre><code>#define ENUM_CLASS(NAME, TYPE, VALUES...) \\\nstruct NAME { \\\n    enum e { VALUES }; \\\n    explicit NAME(TYPE v) : val(v) {} \\\n    NAME(e v) : val(v) {} \\\n    operator e() const { return e(val); } \\\n    private:\\\n        TYPE val; \\\n}\n</code></pre>\n\n<p>This appears to work:\n<a href="http://ideone.com/TYtP2" rel="nofollow">http://ideone.com/TYtP2</a></p>\n'}, {'answer_id': 11632184, 'author': 'Tom', 'author_id': 274460, 'author_profile': 'https://Stackoverflow.com/users/274460', 'pm_score': 7, 'selected': False, 'text': "<p>You can forward-declare an enum in C++11, so long as you declare its storage type at the same time.  The syntax looks like this:</p>\n<pre><code>enum E : short;\nvoid foo(E e);\n\n....\n\nenum E : short\n{\n    VALUE_1,\n    VALUE_2,\n    ....\n}\n</code></pre>\n<p>In fact, if the function never refers to the values of the enumeration, you don't need the complete declaration at all at that point.</p>\n<p>This is supported by G++ 4.6 and onwards (<code>-std=c++0x</code> or <code>-std=c++11</code> in more recent versions).  Visual C++ 2013 supports this; in earlier versions it has some sort of non-standard support that I haven't figured out yet - I found some suggestion that a simple forward declaration is legal, but your mileage may vary.</p>\n"}, {'answer_id': 64886872, 'author': 'Pankaj Gaikar', 'author_id': 3307233, 'author_profile': 'https://Stackoverflow.com/users/3307233', 'pm_score': 0, 'selected': False, 'text': '<p>To anyone facing this for iOS/Mac/Xcode,</p>\n<p>If you are facing this while integrating C/C++ headers in XCode with Objective-C, <strong>just change the extension of your file from .mm to .m</strong></p>\n'}, {'answer_id': 74655121, 'author': 'Sunandan Nandi', 'author_id': 2722779, 'author_profile': 'https://Stackoverflow.com/users/2722779', 'pm_score': -1, 'selected': False, 'text': '<p>This way we can forward declare enum</p>\n<p><code>enum A : int;</code></p>\n<p>please refer the <a href="https://learn.microsoft.com/en-us/cpp/cpp/enumerations-cpp?view=msvc-170" rel="nofollow noreferrer">link</a> for details.</p>\n'}]
['https://Stackoverflow.com/questions/71416', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11437/']