在 c++ 中,函数 structname (void){num_threads = std::thread::hard

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

本文关键字:threads num std hard thread c++ 函数 structname void      更新时间:2023-10-16

当我在我感兴趣的项目中阅读代码时,我遇到了没有函数名称的结构中的函数,也许它也不是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引入了)。