Click here to Skip to main content
15,916,842 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please tell me what the single Semicolon is used for in these 2 examples.
Example 1:
C++
Super(const std::string& str) : mStr(str) {}

Example 2:
C++
Sub(int i) : Super(""), mInt(i) {}




C++
class Super {  
public:  
Super(const std::string& str) : mStr(str) {}
private: std::string mStr;  };

Class Sub : public Super {  
public:
 using Super::Super;
Sub(int i) : Super(""), mInt(i) {}
private int mInt;  };


What I have tried:

Please tell me what the single Semicolon is used for in these 2 examples.
Example 1: Super(const std::string& str) : mStr(str) {}
Example 2: Sub(int i) : Super(""), mInt(i) {}



class Super {
public:
Super(const std::string& str) : mStr(str) {}
private: std::string mStr; };

Class Sub : public Super {
public:
using Super::Super;
Sub(int i) : Super(""), mInt(i) {}
private int mInt; };
Posted
Updated 10-Dec-18 10:33am
v2
Comments
Rick York 10-Dec-18 17:52pm    
There are no semicolons in your examples. Zero. You should probably remind yourself what a semicolon is and what a colon is.

1 solution

You didn't read the documentation (Constructors and member initializer lists - cppreference.com[^]) did you?
 
Share this answer
 
Comments
[no name] 10-Dec-18 16:40pm    
From my Point of view it does not explain the final semicolon. I did not find a proper EBNF for c++ until now :-)
Dave Kreskowiak 10-Dec-18 18:30pm    
There are no semicolons in your statements.

: is a colon
; is a semicolon

CPallini 11-Dec-18 2:54am    
You are right on colon and semicolons, but you are wrong on who wrote them. :-)
Dave Kreskowiak 11-Dec-18 8:09am    
Whoops! Too tired to do this in the middle of the day. :)
CPallini 11-Dec-18 2:55am    
Class declarations must be semicolon-termnated. See, for instance
https://en.cppreference.com/w/cpp/language/class

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