遇到麻烦了
running into trouble with constexpr
我在用常量初始化类时遇到了麻烦:
为什么使用指向同一类成员的指针初始化会导致错误?错误出现没有使用类"使用"!
class A
{
private:
int a;
const int* const aptr;
public:
constexpr A( int _a):
a(_a)
, aptr( &a) // why aptr could not be initialized?
{}
};
class Data { } d1;
class B
{
private:
Data* dptr1;
public:
constexpr B(Data* _p): dptr1( _p) {}
};
class Use
{
static constexpr A a{2}; // fail! error: field initializer is not constant
static constexpr B b{&d1}; // works
};
代码是有效的,Clang接受它;这似乎是一个c++ bug。Use::a.a
的地址是一个地址常量表达式,因为它的计算结果是一个具有静态存储持续时间的对象的地址,所以它可以用来初始化constexpr
对象。
相关文章:
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 查找奇数平方和时遇到麻烦
- CSUF EPP - 你有什么想法(在添加到链接列表末尾时遇到麻烦)
- 我的期末考试遇到了麻烦.代码不断循环回到我的订购菜单,不会显示我的总价
- 作为一个C++新手,我遇到了麻烦
- MySQL 从注入过渡到参数化时遇到麻烦
- C++击球平均值程序使用输入/输出文件打印名称,平均值,最高/最低平均值时遇到麻烦
- 以分类方式插入节点时遇到麻烦
- 在此任务上遇到麻烦,我们需要使用指针和数组来找到文本文件中某些数字的平均值,中值和模式
- C++释放矢量元素占用的内存时遇到的麻烦
- 我在这个程序上遇到了麻烦.只有1个编译错误
- 我的基本蛮力计划遇到了麻烦.具体的类功能
- 我在DFS搜索(树)代码中遇到麻烦.我如何打破递归
- 我在处理字符时遇到麻烦
- 在我的代码覆盖本身时遇到麻烦,我不确定为什么
- 遇到无效旅行的麻烦::d是游戏
- C++处理文件,在制作程序时遇到麻烦
- 在客户端/服务器计算器C 方面遇到麻烦
- 在C 中遇到宏的麻烦
- 在C 的模板编程中遇到了麻烦