簡體   English   中英

在C ++中,函數structname(void){num_threads = std :: thread :: hardware_concurrency();}的作用是什么? 我怎么理解?

[英]What is the function structname (void){num_threads = std::thread::hardware_concurrency();} for in c++? How can I understand it?

當我在自己感興趣的項目中閱讀代碼時,遇到了結構中沒有函數名稱的函數,也許不是lambda表達式capture-> return-type {body},我只是不知道該函數是哪種?

// file.cc
struct AppSettings
{

    std::string mesh_name;

    std::size_t num_threads;

    AppSettings (void)
    {
        num_threads = std::thread::hardware_concurrency();
    }
};

任何人都知道我應該如何理解此功能
AppSettings (void) {num_threads = std::thread::hardware_concurrency();}

那是該類的構造函數

這是一個特殊的成員函數,在實例化該類的實例時會自動執行。

給它的參數列表(void)是給它的參數列表中使用老式的方法()即沒有參數。

有關更多信息,請參見C ++書中有關類的章節( 注意struct引入了class )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM