中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

策劃一個(gè)網(wǎng)站網(wǎng)站推廣策劃方案

策劃一個(gè)網(wǎng)站,網(wǎng)站推廣策劃方案,網(wǎng)站封裝成app可以做熱更新,做網(wǎng)站 以圖搜貨C筆記之將定時(shí)器加入向量并設(shè)置定時(shí)器的ID為i code review! 文章目錄 C筆記之將定時(shí)器加入向量并設(shè)置定時(shí)器的ID為i關(guān)于代碼中的void operator()() 運(yùn)行 代碼 #include <chrono> #include <iostream> #include <thread> #include <vector>// 定義定時(shí)…

C++筆記之將定時(shí)器加入向量并設(shè)置定時(shí)器的ID為i

code review!

文章目錄

  • C++筆記之將定時(shí)器加入向量并設(shè)置定時(shí)器的ID為i
    • 關(guān)于代碼中的void operator()()

在這里插入圖片描述
運(yùn)行
請?zhí)砑訄D片描述
代碼

#include <chrono>
#include <iostream>
#include <thread>
#include <vector>// 定義定時(shí)器類
class Timer {public:Timer(int id, std::chrono::seconds interval) : id(id), interval(interval) {}void operator()() {std::this_thread::sleep_for(std::chrono::seconds(interval));std::cout << "Timer " << id << " expired!" << std::endl;}private:int id;std::chrono::seconds interval;
};// 定義一個(gè)函數(shù),用于將定時(shí)器加入向量并設(shè)置定時(shí)器的ID為i
void addTimer(std::vector<Timer> &timers, int i, std::chrono::seconds interval) {Timer timer(i, interval);timers.push_back(timer);
}int main() {// 創(chuàng)建一個(gè)包含3個(gè)定時(shí)器的向量std::vector<Timer> timers;addTimer(timers, 1, std::chrono::seconds(1));addTimer(timers, 2, std::chrono::seconds(2));addTimer(timers, 3, std::chrono::seconds(7));// 啟動(dòng)定時(shí)器并等待它們到期for (auto &timer : timers) {std::thread t(std::ref(timer));t.detach(); // 將定時(shí)器線程分離,使其在后臺(tái)運(yùn)行}std::this_thread::sleep_for(std::chrono::seconds(10)); // 等待10秒鐘,使所有定時(shí)器都有足夠的時(shí)間到期return 0;
}

關(guān)于代碼中的void operator()()

Timer timer(i, interval); 這一行實(shí)際上是在創(chuàng)建 Timer 對(duì)象,并且在這個(gè)過程中沒有直接使用了 operator()() 函數(shù)調(diào)用運(yùn)算符。
operator()() 函數(shù)調(diào)用運(yùn)算符的使用方式是通過將 Timer 對(duì)象傳遞給 std::thread 的構(gòu)造函數(shù)來實(shí)現(xiàn)的,如下所示:

std::thread t(std::ref(timer));

這里的 timer 是一個(gè) Timer 類型的對(duì)象。通過傳遞 std::ref(timer)std::thread 構(gòu)造函數(shù),你實(shí)際上在創(chuàng)建一個(gè)新的線程,并在這個(gè)新線程中調(diào)用了 timer 對(duì)象的 operator()() 函數(shù)。這就是代碼中使用 operator()() 函數(shù)的地方。

http://www.risenshineclean.com/news/49093.html

相關(guān)文章:

  • 如何做國外外貿(mào)網(wǎng)站windows優(yōu)化大師收費(fèi)嗎
  • 開封做網(wǎng)站推廣熱門關(guān)鍵詞排名查詢
  • 松崗建網(wǎng)站十八大禁用黃app入口
  • 網(wǎng)站制作咨詢電話百度引擎搜索
  • 房產(chǎn)中介如何做網(wǎng)站seo推廣服務(wù)哪家好
  • 騰訊云做淘客網(wǎng)站百度關(guān)鍵詞搜索排名代發(fā)
  • 網(wǎng)站備案密碼怎么找回自己開一個(gè)培訓(xùn)機(jī)構(gòu)流程
  • 蘇州市建設(shè)工程交易中心網(wǎng)站河南百度關(guān)鍵詞優(yōu)化排名軟件
  • 小程序怎么做微網(wǎng)站鏈接微信上如何投放廣告
  • 營銷手機(jī)網(wǎng)站seo技術(shù)自學(xué)
  • 簡述使用asp建設(shè)動(dòng)態(tài)網(wǎng)站頁面優(yōu)化
  • 招聘網(wǎng)站設(shè)計(jì)方案培訓(xùn)網(wǎng)站搭建
  • 簡約型網(wǎng)站建設(shè)站外推廣方式有哪些
  • 企業(yè)為什么做網(wǎng)站如何做網(wǎng)站賺錢
  • saas 做網(wǎng)站qq群怎么優(yōu)化排名靠前
  • 免費(fèi)個(gè)人簡歷表電子版武漢企業(yè)seo推廣
  • 做網(wǎng)站平臺(tái)成本石家莊今天最新新聞?lì)^條
  • 網(wǎng)站如何做點(diǎn)擊鏈接廣州aso優(yōu)化公司 有限公司
  • c2b模式的電商平臺(tái)網(wǎng)站有哪些好看的友情鏈接代碼
  • 友情鏈接添加在網(wǎng)站中有什么用友情鏈接交換平臺(tái)有哪些
  • 怎樣做外貿(mào)網(wǎng)站建設(shè)怎么出售友情鏈接
  • 找個(gè)網(wǎng)站開發(fā)的師傅外鏈工具xg
  • 易語言可以做網(wǎng)站后端東莞市優(yōu)速網(wǎng)絡(luò)科技有限公司
  • 舟山網(wǎng)站開發(fā)網(wǎng)絡(luò)營銷和網(wǎng)上銷售的區(qū)別
  • 高端建設(shè)網(wǎng)站公司哪家好網(wǎng)頁版百度云
  • 在家建設(shè)一個(gè)網(wǎng)站需要什么材料企業(yè)網(wǎng)站設(shè)計(jì)畢業(yè)論文
  • 武漢網(wǎng)站建設(shè)公司 排名如何免費(fèi)制作自己的網(wǎng)站
  • wordpress網(wǎng)站秒開上海seo網(wǎng)站優(yōu)化
  • 奧鵬網(wǎng)頁設(shè)計(jì)與網(wǎng)站建設(shè)百度開發(fā)者平臺(tái)
  • 怎么做自己優(yōu)惠券網(wǎng)站天門seo