C++ c+;中的函数structname(void){num_threads=std::thread::hardware_concurrency();}是什么+;?我怎么能理解呢?
当我阅读我感兴趣的项目中的代码时,我在struct中遇到了没有函数名的函数,可能它也不是lambda表达式capture->返回类型{body},我只是不知道这个函数是什么类型的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
// 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可能不是个坏主意。”