aconst_iterator与 一样吗const iterator?如果不是有什么区别?如果是的话,为什么标准使用const_iteratorwhenconst iterator已经有意义?
例如,这两个声明完全相同吗?
string& replace (const_iterator i1, const_iterator i2, const string& str);
string& replace (const iterator i1, const iterator i2, const string& str);
如果我们有一个类H有一些operator()重载。如何从这些成员函数创建线程而不用实例化类中的对象H。考虑下面的代码
#include<iostream>
#include<thread>
class H {
public:
void operator()(){
printf("This is H(), I take no argument\n");
}
void operator()(int x){
printf("This is H(), I received %d \n",x);
}
};
int main(){
int param = 0xD;
//No object created
std::thread td_1 = std::thread(H());
std::thread td_2 = std::thread(H(),param);
td_1.join();
td_2.join();
//From an object
H h;
std::thread td_3 = std::thread(h);
std::thread td_4 = std::thread(h,param);
td_3.join();
td_4.join();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
产生输出:
#include<iostream>
#include<thread>
class H {
public:
void …Run Code Online (Sandbox Code Playgroud)