这是糟糕的c++风格还是编辑错误?
Is this a bad C++ style or an editor error?
我在一个新的c++编辑器(CLion)中有这个代码:
struct screenPoint {
float x = 0, y = 0;
screenPoint(float x_, float y_): x{x_}, y{y_}{}
};
struct position {
screenPoint ul;
float width = 0, height = 0;
position(screenPoint p, float w, float h): ul{p},width{w},height{h}{}
};
接近末尾是初始化语句ul{p}
,我认为这是使用大括号初始化的有效c++方式。然而,CLion抱怨:
Incompatible types in initialiser: Types 'float' and 'screenPoint' are not compatible.
注意:没有编译错误或警告,代码按预期工作。
如果我将其更改为ul(p)
,错误就会消失。
现在,我知道screenPoint
没有接受另一个screenPoint
的构造函数,但是在这样的初始化中有必要吗?
编辑错误。具有相同类型元素的列表初始化应该调用隐式复制构造函数。
有一个关于复制聚合的核心语言缺陷(1467),但这不是一个聚合。
这肯定是CLion的问题。在跟踪器中:https://youtrack.jetbrains.com/issue/CPP-6939
相关文章:
- Qt VTK交互风格的信号到小部件
- 我可以使用条件运算符初始化C风格的字符串文字吗
- Visual Studio 2019:插入多个C++风格的单行注释
- 在createdialog创建的窗口中捕获用于编辑控件的OnMouseMove消息
- 如何在本地机器上运行c++和javascript客户端代码(hackerbank风格)
- 编辑文件中的文本
- 有没有办法在远程设备上打开和编辑visual Studio 2017解决方案
- SetDlgItemInt 不会更改嵌入资源的编辑框
- 我无法在Visual Studio代码中使用CIN输入答案,它说输入您的年龄,但它说只读文本编辑器如何解决这个问题?
- C++,Qt:仅在双击后编辑qtablewidget项目
- 重载运算符<<采用谷歌 C++ 风格
- 编辑字符串以包含括号 c++ 之间的变量
- C++许多 SFINAE 风格的过载
- Arduino函数无法编辑数组
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- "未定义对'WinMain@16'的引用"gcc 编辑器中的错误
- C++MFC编辑框处理双击
- 是否可以使用指针访问变量以避免直接编辑变量?
- 我的主窗口在创建时或单击更新区域时是否会收到编辑控件?
- 这是糟糕的c++风格还是编辑错误?