c++11 - Access static constexpr std::array without out-of-class definition -
i have class defines arrays.
points.hpp
class points { public: static constexpr std::array< double, 1 > a1 = { { +0.0 } }; static constexpr std::array< double, 2 > a2 = { { -1.0 / std::sqrt( 3.0 ), +1.0 / std::sqrt( 3.0 ) } }; };
my main file uses these arrays.
main.cpp
#include "points.hpp" int main() { // example on how access point. auto point = points::a2[0]; // point. }
when compile code, using c++11 , g++ 4.8.2, following linker error:
undefined reference `points::a2'
i attempted create points.cpp file compiler can create object file it.
points.cpp
#include "points.hpp"
but did not fix linker error.
i under impression possible initialize variables static constexpr in c++11 in class declaration, , access them way i'm doing it, shown in question: https://stackoverflow.com/a/24527701/1991500
do need make constructor points , instantiate class? doing wrong?
any feedback appreciated! thanks!
as per @dyp suggestion, looked definition of static data members.
my problem requires me define static member variables of points class.
following examples in these questions:
is constexpr array odr-used when subscripted?
and
defining static members in c++
i need add:
// in .cpp constexpr std::array< double, 1 > points::a1;
Comments
Post a Comment