Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
1.67/5 (3 votes)
See more:
Please tell me what the single colon is used for in these 2 examples.
Example 1:

Super(const std::string& str) : mStr(str) {}

Example 2:

Sub(int i) : Super(""), mInt(i) {}

What I have tried:

Please tell me what the single colon is used for in these 2 examples.
Example 1:

Super(const std::string& str) : mStr(str) {}

Example 2:

Sub(int i) : Super(""), mInt(i) {}
Posted
Updated 10-Dec-18 22:31pm
Comments
KarstenK 11-Dec-18 2:27am    
it standard language syntax. Read the documentations.

It is separating the derived class constructor from the base class constructor and from member initializations. The general format is :
C++
DerivedClass( derived_args, base_arguments )
    : BaseClass( base_arguments )
    , m_Member1( initial_value1 )
    , m_Member2( initial_value2 )
{
   // constructor implementation
}
I recommend reading this tutorial at the C++ reference site: Classes (I) - C++ Tutorials[^]
 
Share this answer
 
v2
Please study C++ Language Reference | Microsoft Docs[^] you will learn much faster than by posting basic questions here.
 
Share this answer
 

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