September 1998
Intermediate to advanced
848 pages
20h 13m
English
In C, a global const has external linkage, but in C++ it has internal linkage. That is, the C++ declaration
const double PI = 3.14159;
is equivalent to the C declaration
static const double PI = 3.14159;
providing both declarations are outside of any function. The C++ rule has the goal of making it simpler to use const in header files. If the constant has internal linkage, then each file that includes the header file gets its own copy of the constant. If a constant has external linkage, then one file has to have a defining declaration and the other files have to have a reference declaration, one that uses the keyword external.
Incidentally, C++ can use the keyword extern to make a const value have external linkage, so both ...
Read now
Unlock full access