C++C++14C++17Learn C++

How Can We Use The is_final Type Trait In C++ 14?

How Can We Use The is final Type Trait In C++ 14

In C++11, the final specifier is used for a function or for a class that cannot be overridden by derived classes, and there was no way to check if that class or method is the final. In C++14, there is a std::is_final type trait that can be used to detect if a class or a method is marked as a final or not. In this post, we explain how we can use the std::is_final type trait in C++14 and C++17.

What is the final specifier in modern C++?

The final specifier (keyword) is used for a function or for a class that cannot be overridden by derived classes. Regarding virtual overrides, C++11 tends to tighten the rules, to detect some problems that often arise. To achieve this goal C++11 introduced a new contextual keyword, the final specifier. The final keyword specifies that a method cannot be overridden, or a class cannot be derived. If you want to learn more about it, here it is,

What is the std::is_final type trait in C++ 14?

The std::is_final type trait (UnaryTypeTrait) defined in <type_traits> detects if a class is marked final and returns true or false boolean. If a class or method is final, it returns the member constant value equal to true, if not returns the value is false.

Here is the syntax (since C++14).

How can we use the std::is_final type trait in C++ 14?

We can use the std::is_final type trait to check classes if it is marked as a final or not. Here is a simple example.

Is there a full example about the std::is_final type trait ?

Here is a full example about to use the std::is_final type trait in C++14 and C++17.

For more information, please see https://cplusplus.github.io/LWG/issue2112

How Can We Use The is final Type Trait In C++ 14 C++ Builder logo

C++ Builder is the easiest and fastest C and C++ compiler and 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.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.

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.

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
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?

C++C++11Introduction to C++Learn C++Syntax

Full List Of Features In C++ 11

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

How To Use Basic Methods Of Strings In C++?