我刚刚阅读并了解是否可以使用new运算符初始化C++ 11中的数组,但它并没有完全解决我的问题.
这段代码在Clang中给出了一个编译错误:
struct A
{
A(int first, int second) {}
};
void myFunc()
{
new A[1] {{1, 2}};
}
Run Code Online (Sandbox Code Playgroud)
我期望{{1,2}}使用单个元素初始化数组,然后使用构造函数args {1,2}初始化,但是我收到此错误:
error: no matching constructor for initialization of 'A'
new A[1] {{1, 2}};
^
note: candidate constructor not viable: requires 2 arguments, but 0 were provided
A(int first, int second) {}
^
note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
struct A
^
Run Code Online (Sandbox Code Playgroud)
为什么这种语法不起作用?
我正在使用 LLDB 调试 Qt 应用程序。在断点处我可以写
(lldb) p myQString.toUtf8().data()
Run Code Online (Sandbox Code Playgroud)
并查看 myQString 中包含的字符串,因为 data() 返回 char*。我希望能够写
(lldb) p myQString
Run Code Online (Sandbox Code Playgroud)
并得到相同的输出。这对我不起作用:
(lldb) type summary add --summary-string "${var.toUtf8().data()}" QString
Run Code Online (Sandbox Code Playgroud)
是否可以编写一个像这样的简单格式化程序,或者我是否需要了解 QString 的内部结构并编写一个 python 脚本?
或者,我是否应该使用 LLDB 来以这种方式查看 QStrings?
我正在开发Qt项目,并且已经从他们的安装程序中将Qt安装到了我的计算机上。在Visual Studio中,调试到Qt源代码很简单:当我在未知文件中输入函数时,它将打开文件浏览器以让我找到原始Qt源代码。
Xcode或LLDB中是否有等效功能?