constexpr

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
george_21
Posts: 1
Joined: June 14th, 2014, 3:29 pm

constexpr

Post by george_21 » July 21st, 2018, 10:41 pm

Whenever I try to create a constexpr int I get an error but when I add the static keyword it seems to work. Why a constexpr int always has to be a static one??

MrGodin
Posts: 721
Joined: November 30th, 2013, 7:40 pm
Location: Merville, British Columbia Canada

Re: constexpr

Post by MrGodin » July 22nd, 2018, 12:50 am

Curiosity killed the cat, satisfaction brought him back

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: constexpr

Post by albinopapa » July 22nd, 2018, 4:52 am

global and function level constexpr don't have to have static, but member constexpr variables do because they are scoped to the class, but not a part of any one instance of the class.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: constexpr

Post by albinopapa » July 22nd, 2018, 4:54 am

Oh, another thing I've learned is if you try to take a reference or address of a constexpr, you will have to make sure to define or initialize the variable in namespace scope like any other static variable.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

Post Reply