C++ – Declarations

A declaration is an all encompassing term for anything that tells the compiler about an identifier. In order to use the identifier the compiler must know what it means: is it a type name, a variable name, a function name or something else?

A definition defines the storage, value, body, or contents of the declaration.

There must be exactly one definition of an entity.

A header file contains classes and functions that can be used for multiple application. A header file typically has a .h extension and a source file which contains the functionality related to the header file. The source file typically has an extension of .cpp

scope is a region of source code that contains declarations. When the compiler knows the scope name then it can look it up and determine how it will be used. Think of it as a dictionary of names to map to declarations. Classes and namespaces define scope names while statement blocks, function bodies, and unnamed namespaces define unnamed scopes.

A general rule is that the code inside of a curly brace denotes a scope. In conjunction the outermost scope is outside of the curly braces and is referred to as global scope.

 

<< Language Basics

Data Types >>