C++C++11C++14C++17Introduction to C++Learn C++

What is a Forward Declaration enum Enumeration in C++?

Understanding how to correct declare variables is important in programming, especially in a modern C++ Application. There is an enumeration method that allows you to easily enumerate (count or determine their place in an order) values in variables. In C++, enumeration is very important and widely used. In C++, enumeration can be done with an enum keyword which can be used in unscoped and scoped enumerations. There are some subtleties to declaring and using an enum especially if you use forward declaration of the enum. In this post, we explain what an enum is, what a forward declaration is, and how to declare a forward enum Enumeration in Modern C++ along with some easy-to-understand examples.

What is (enum) enumeration in Modern C++?

An enumeration is used to declare constants in a range of values easily. It may include several explicitly-named constants which are also called as enumerators. In C++, enumeration can be done with the enum keyword which is also known as enum-key. An enum can be used in two ways in C++. These are:

  • Unscoped enumeration
  • Scoped enumeration (strongly typed enums)

Now, let’s see very simple some enum examples.

or you can explicitly declare their values too:

What is a forward declaration enum enumeration in Modern C++?

C++11 was the first standard to introduce forward declaration of an enum. We can declare an enumeration without providing a list of enumerators. Such declarations would not be definitions and can be provided only for enumerations with fixed underlying types. Here is a simple example.

An enumeration can then be re-declared, possibly providing the missing list of enumerators, but the re-declaration must match the previous declaration. This feature is one of the C++11 features added to CLANG compilers like BCC32c, and other compiler like BCC32 etc.

Is there an example of a forward declaration enum enumeration in Modern C++?

Here is a simple example that shows how you use a forward declaration enum, how to define an enum, and how you can use it.

When we use forward declaration enum, it must specify (implicitly or explicitly) the underlying size of the enum. Here are some examples,

Here are some more forward declaration enum examples that are acceptable.

Here are some invalid enum usage examples.

Is there a full example of forward declaration enum enumeration in modern C++?

Here is a full forward declaration of enum example in C++.

Forward declaration for an enum is a feature supported by both BCC32 and the Clang-enhanced C++ compilers. For more information about this feature, see Forward Declaration of Enums (C++11).

These are other enumeration examples. These are explained in other articles of LearnCPlusPlus.org. Use this dynamic search to find out more information on how to declare and use enum enumeration types in C++: https://learncplusplus.org/?s=enum

What is A Forward Declaration enum Enumeration In C++ The C++ Builder Logo

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

Learn Default Constructors Of Classes In Modern C++

Artificial Intelligence TechC++C++11C++14C++17Learn C++

How To Develop Special AI Activation Functions In C++?

Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?