为什么下面的C++代码无法编译?
#include <utility>
int main() {
int x[6];
int y[6];
std::pair<int[6], int[6]> a(x, y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
例如 MSVC 给出以下错误:
错误 C2661: 'std::pair<int [6],int [6]>::pair': 没有重载函数需要 2 个参数
感谢使用C++替代品构造数组的评论,但我也想知道代码无法编译的原因。
我对下面代码的成功编译感到非常困惑。函数“g”中的变量“t”显然是左值。当'g'返回到主函数时,'t'应该被复制。但是线程对象是不可复制的,那为什么会编译成功呢?
#include <thread>
void some_other_function(int) {
return;
}
std::thread g()
{
std::thread t(some_other_function,42);
return t;
}
int main() {
g();
return 0;
}
Run Code Online (Sandbox Code Playgroud)