-1

When I reading code in project of my interest, I come across the function in struct without function name, and maybe it is not the lambda expression capture->return-type{body} either, i just donnot know what kind of this function is?

// file.cc
struct AppSettings
{

    std::string mesh_name;

    std::size_t num_threads;

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

anyone knows how should i understand this function
AppSettings (void) {num_threads = std::thread::hardware_concurrency();}?

YSC
  • 38,212
  • 9
  • 96
  • 149
  • 1
    If you know about lambda expressions but not constructors, you may have begun your C++ studies at the wrong end. – molbdnilo Jan 02 '19 at 15:26
  • Thank you for your answer, i am almost a beginner of c++... i am used to the common usage of the constructor but forget the default one – philleeroi Jan 02 '19 at 15:26

1 Answers1

2

That is the class's constructor.

This is a special member function that's automatically executed when an instance of the class is instantiated.

Giving it the parameter list (void) is an old-fashioned way of giving it the parameter list (), i.e. no parameters.

For more information, consult the chapter in your C++ book about classes (bearing in mind that struct introduces a class).

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055