answersLogoWhite

0

A C++ qualifier is a keyword that contains semantic information related to a type. In other words, they are used to qualify a type.

The C++ qualifiers are const, mutable, restrict and volatile. Qualifiers do not alter the type's storage capacity nor how that storage is interpreted in any way.

The const qualifier is used to qualify that a type cannot be modified once it is initialised. As such, constants must be initialised at the point of instantiation, like so:

const int meaning_of_life = 42;

The const qualifier can also be used to qualify function arguments, like so:

void foo(const int x) { ... }

In this case, x is instantiated and initialised whenever the function is called.

The const qualifier can also be used with class instance methods (non-static member functions):

void foo::method() const { ... }

In this case, the const qualifier applies to the hidden this pointer, and thus ensures that the instance's non-mutable member attributes cannot be modified. Constant member methods may only access other other constant member methods of the same instance.

The mutable qualifier applies to class instance member data only. Data that is qualified as mutable may be modified by any method, including constant methods. You will typically use this feature for internal class data that does not alter the outward appearance of an object in any way. For instance, you might use internal caches or counters that do not alter the outward appearance of an object. If these members were not qualified as mutable, you wouldn't be able to modify them from within any constant methods. Note that the compiler uses a bitwise constant check to ensure all members remain unchanged within a constant method. The mutable keyword simply excludes the specified members from this check.

The restrict qualifier is not strictly a qualifier as it is not part of the C++ standard (it was introduced in C99) but some compilers support it. The restrict qualifier applies to pointers and references and merely provides a promise to the compiler that the object being referenced will only be access through the restricted reference or through copies of that reference.

The volatile qualifier denotes that a memory location may be modified by hardware or by external processes.

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

What are data type qualifiers?

In programming languages, a type qualifier indicates the special properties of a variable. Type qualifiers can be used for code optimization and for finding defects. In C/C++ one of the popular type qualifiers is the const qualifire. It is used to fix the value of a variable after the variable is initialized.


Is Austria competing in the the football world cup?

Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.Austria did compete in the qualifiers in Europe to reach the 2014 World Cup qualifiers, but did not qualify to play in the World Cup.


What are qualifiers in essays?

this qualifiers and essays in my oponuon evry people enargy


What is the advantages of storage class in c?

advantage of storage classes


For which trigger timing can you reference the NEW and OLD qualifiers?

For which trigger timing can you reference the NEW and OLD qualifiers?


Explain the different access storage specifiers available in c?

The storage class specifiers in C and C++ are:autoexternmutableregisterstatictypedefA storage class specifier is used to refine the declaration of a variable, a function, and parameters


What is storage classes in c plus plus?

AUTO EXTERN STATIC are the storage classes in c++


What has the author C A S Padfield written?

C. A. S. Padfield has written: 'The storage of apples and pears' -- subject(s): Apples, Food storage pests, Pear, Storage


What is the by default storage class of any variable in c?

automatic storage class


C program for storage representation of 2-D array?

Wright a 'C' program for storage representation of 2-D array.


What are the storage classes in c?

A storage class defines the visibility and lifetime of variables or/and functions within a C Program. There are following storage classes which can be used in a C Program: auto register static extern


What are describing nouns called?

qualifiers