根据C++ 11规则,默认情况下会生成6个内容(默认构造函数,复制构造函数,移动构造函数,复制赋值,移动赋值和析构函数).根据第二个规则,当定义任何自定义副本,移动或析构函数时,不会生成这些默认操作.但是在我之后的代码中并非如此.但是这段代码无法编译错误
call to implicitly deleted copy constructor of 'Uni'
Run Code Online (Sandbox Code Playgroud)
当我为Uni编写自己的复制构造函数时,一切正常.(在代码中注释,供参考)
任何想法都非常感激.
最后,我在Mac上运行它,使用LLVM编译器运行Xcode.
非常感谢...
#include <iostream>
class A
{
public:
A(int i) :num{i}
{
std::clog<< "ctor A() num = " << num << "\n";
}
A( A const &aRef)
:num{aRef.num}
{
std::clog << " copy ctor A( A const &aRef) num = " << num << "\n";
}
int value()
{
return num;
}
private:
int num;
};
class Uni
{
public:
Uni(A* aptr) : up{aptr}
{
std::clog << " …Run Code Online (Sandbox Code Playgroud) 为什么动态创建线程向量是错误的?我收到编译错误
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xmemory0(593):错误 C2280:'std::thread::thread(const std::thread &)':试图引用已删除的函数
其次是很多其他的东西。
#include <iostream>
#include <thread>
#include <vector>
using std::vector;
using std::thread;
using std::cout;
class obj_on_thread {
public:
void operator()()
{
std::cout << "obj on thread\n";
}
};
void function_on_thread() {
std::cout << "function on thread\n";
}
auto named_lambda = []() { std::cout << "named_lambda_on_thread\n"; };
int main(){
obj_on_thread obj;
vector<thread> pool {
thread{ obj },
thread{ function_on_thread },
thread{ named_lambda },
thread{ []() { cout << "anonymous lambda on thread\n"; …Run Code Online (Sandbox Code Playgroud)