c++ - Does removing constexpr change linkage? -


i have simple config struct defined in header contains series of other simple structs containers static variables. here's example:

// config.h     struct config {      struct server {         static constexpr const char* url = "http://example.com";         static constexpr float polling_interval = 1.0f;     };      struct window {         static constexpr int width = 1920;         static constexpr int height = 1200;     };     }; 

i include header file need , access variables this: config::window::width

this works fine @ point needed load values file changed variable declarations not constants (e.g. static constexpr int width = 1920; became static int width;). linker complains of undefined symbols variables. isn't linkage static constexpr objects same static objects? there else i'm missing?

it has nothing linkage.

static constants, value specified in declaration, usable constant expressions, , don't need definitions usage.

static variables need definitions if aren't constant (so value needs stored somewhere @ runtime) or if they're odr-used (roughly speaking, if take address or form reference them, again means need exist somewhere @ runtime).


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -