C++C++17Introduction to C++Learn C++

Learn About Explicit Specifier in C++ Classes

What is Explicit Specifier ? How can we use Explicit Specifiers in Classes ? Here are the explanations with examples below,

Classes are are the blueprint that has properties and methods for the objects and they are user-defined data types that we can use in our program, and they work as an object constructor. Classes defined in C++ by using keyword class followed by the name of the class.

Objects are an instantiation of a class, In another term. In C++ programming, most of the commands are associated with classes and objects, along with their attributes and methods. 

The Explicit Specifier defined with ‘explicit‘ statement and it can be used alone or with a constant expression in C++ Classes that the function is explicit if and only if that constant expression evaluates to true. It specifies that a constructor or conversion function or deduction guide is explicit. It cannot be used for implicitly conversions and copy initialization.

Syntax,

An example in a Class,

An example with ‘operator’ statement in a Class,

The explicit specifier may only appear within the decl-specifier-seq of the declaration of a constructor or conversion function within its class definition.

Get started building powerful apps with C++Builder!

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
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

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

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

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

How To Learn The Move Constructors In Modern C++?