[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/language/constant_initialization [Back]  [Original]

cppreference.com
cppreference.com

cppreference.com

.

static T & = constexpr; (1)
static T = constexpr; (2)

( C++11) . :

1) ( C++11) , lvalue ( C++11)glvalue ( C++11), ( ) ( C++11) , ( ) .
2) ( C++11) PODType ( C++11) ( ), , .
3) , , constexpr ( ) , .
( C++11)

, , , , ( C++11) , .

( C++11) , , , , .

, (, .data). const, , , (, .rodata).

#include <iostream>
#include <array>

struct S
{
    static const int c;
};

const int d = 10 * S::c; //  : S::c   
                         // ,     const
const int S::c = 5;      //  ,  
                         //  

int main()
{
    std::cout << "d = " << d << '\n';
    std::array<int, S::c> a1; // OK: S::c  
//  std::array<int, d> a2;    // : d    
}

:

d = 50

C++:

CWG 441 C++98
CWG 1489 C++98 ,
CWG 1747 C++98
CWG 1834 C++11 xvalue
CWG 2026 C++98 ,
,
,
CWG 2366 C++98
( )


Web Proxy Viewer  |  New URL  |  Original Page