mercredi 27 décembre 2017

C++: passing a structure to a function, cannot understand syntax

Sorry for the very bad title but I didn't really know what to write.

I have the following library Neural_Network.h with the class Network in C++:

class Network{
    public:
       struct Settings
       {
           uint32_t                        m_numInputs;
           uint32_t                        m_numHidden;
           uint32_t                        m_numOutputs;
       };
       Network(Settings const& settings);
}

Then, in the Neural_Network.cpp file it is implemented in the following way:

Network::Network( Settings const& settings )
    : m_numInputs( settings.m_numInputs )
    , m_numHidden( settings.m_numHidden )
    , m_numOutputs( settings.m_numOutputs )
{
    assert( settings.m_numInputs > 0 && settings.m_numOutputs > 0 && settings.m_numHidden > 0 );
    InitializeNetwork();
    InitializeWeights();
}

I don't really understand why I do need the: :m_numInputs( settings.m_numInputs ), , m_numHidden( settings.m_numHidden ) , m_numOutputs( settings.m_numOutputs ) after the name of the function. What is its purpose?

Thank you very much for your reply and please edit the question if you have a better way of asking this.

Aucun commentaire:

Enregistrer un commentaire