Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have read the following C ++ code:

CEnumContext::CEnumContext(void)
: m_SearchContainer(NULL)
, m_SearchPattern(NULL)
, m_fileTimeFrom(0)
, m_fileTimeTo(0)
, m_FileFlags(FILE_ATTRIBUTE_NORMAL)
, m_maxDepth(-1)
, m_depth(0)
{
m_maxFileSize.QuadPart = 0;
m_SearchPattern = _tcsdup(TEXT("*.*"));
}

: m_SearchContainer(NULL)
, m_SearchPattern(NULL)
, m_fileTimeFrom(0)
, m_fileTimeTo(0)
, m_FileFlags(FILE_ATTRIBUTE_NORMAL)
, m_maxDepth(-1)
, m_depth(0) are variables.
I do not understand what they use here for and the purpose.
Help me explain them! thanks.

What I have tried:

: m_SearchContainer(NULL)
, m_SearchPattern(NULL)
, m_fileTimeFrom(0)
, m_fileTimeTo(0)
, m_FileFlags(FILE_ATTRIBUTE_NORMAL)
, m_maxDepth(-1)
, m_depth(0) are variables.
I do not understand what they use here for and the purpose.
Help me explain them! thanks.
Posted
Updated 2-Sep-19 23:14pm

This is C++ syntax for constructor initialization of members. Some explanation and examples from Microsoft.
 
Share this answer
 
This part of the code is called an initializer list. See Constructors and member initializer lists - cppreference.com[^] for in-depth explanations.

P.S.:
A short explanation: the ':' indicates the start of an initializer list. Before the ':' is a call to a constructor, after the ':' comes a comma-separated list of member variables and the values that are used to initialize them.

For example in this case, we can see that the class CEnumContext has a member variable called m_SearchContainer, which is initialized with the value NULL.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900