首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何声明constexpr extern?

如何声明constexpr extern?
EN

Stack Overflow用户
提问于 2018-04-03 05:11:57
回答 2查看 0关注 0票数 0

是否可以声明一个变量extern constexpr并将其定义在另一个文件中?

我试过了,但编译器给出了错误:

Declaration ofconstexprvariable 'i' is not a definition

在.h中:

extern constexpr int i;

在.cpp中:

constexpr int i = 10; 
EN

回答 2

Stack Overflow用户

发布于 2018-04-03 13:44:15

标准给出的一些例子:

  constexpr void square(int &x);  // OK: declaration
  constexpr int bufsz = 1024;  // OK: definition
  constexpr struct pixel {  // error: pixel is a type
    int x;
    int y;
    constexpr pixel(int);  // OK: declaration
  };

  extern constexpr int memsz; // error: not a definition
票数 0
EN

Stack Overflow用户

发布于 2018-04-03 15:01:38

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100003775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档