Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c+;中的函数structname(void){num_threads=std::thread::hardware_concurrency();}是什么+;?我怎么能理解呢?_C++ - Fatal编程技术网

C++ c+;中的函数structname(void){num_threads=std::thread::hardware_concurrency();}是什么+;?我怎么能理解呢?

C++ c+;中的函数structname(void){num_threads=std::thread::hardware_concurrency();}是什么+;?我怎么能理解呢?,c++,C++,当我阅读我感兴趣的项目中的代码时,我在struct中遇到了没有函数名的函数,可能它也不是lambda表达式capture->返回类型{body},我只是不知道这个函数是什么类型的 // file.cc struct AppSettings { std::string mesh_name; std::size_t num_threads; AppSettings (void) { num_threads = std::thread::hardw

当我阅读我感兴趣的项目中的代码时,我在struct中遇到了没有函数名的函数,可能它也不是lambda表达式capture->返回类型{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)
是给它参数列表
()
的一种老式方式,即没有参数


更多信息,请参阅有关课程的章节(记住)。

如果你知道lambda表达式,但不知道构造函数,你可能已经开始了错误的C++学习。谢谢你的回答,我几乎是C++初学者。我习惯了构造函数的常用用法,但忘记了默认用法谢谢你的回答。也许我真的应该更仔细地学习C++底漆……“PhilLee可能不是个坏主意。”