STL Static-Const Member Definitions
Posted
by javery
on Stack Overflow
See other posts from Stack Overflow
or by javery
Published on 2010-04-23T01:41:03Z
Indexed on
2010/04/23
1:43 UTC
Read the original article
Hit count: 290
How does the following work?
#include <limits>
int main()
{
const int* const foo = &std::numeric_limits<int> ::digits;
}
I was under the impression that in order to take an address of a static const
-ant member we had to physically define it in some translation unit in order to please the linker. That said, after looking at the preprocessed code for this TU, I couldn't find an external definition for the digits
member (or any other relevant members).
I tested this on two compilers (VC++ 10 and g++ 4.2.4) and got identical results (i.e., it works). Does the linker auto-magically link against an object file where this stuff is defined, or am I missing something obvious here?
© Stack Overflow or respective owner