c++11 - Why constexpr data members are not implicitly static? -


if this:

constexpr int len = 100; 

len variable defined const without need of typing const keyword.
have static storage, without need type static keyword.

from other hand, if same in class:

struct a{    constexpr static int size = 100; }; 

size still defined const without need of typing const keyword,

however size not static data member.
need type static explicitly. if don't there compilation error.

question is:
reason of need explicitly type static?

constexpr should not imply static, because having constexpr without static makes sense. consider:

#include <iostream>  struct dim {     constexpr dim(int a,int b) : a(a), b(b) {}     constexpr int prod() const { return a*b; }     int a,b; };  int main() {     constexpr dim sz(3,4);     int arr[ sz.prod() ];     std::cout << sizeof(arr) << std::endl; } 

it should not imply static outside of class definition since static there means 'local translation unit' , constexpr not require that.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -