请告诉我这些例子中使用的单个分号是什么。 [英] Please tell me what the single semicolon is used for in these examples.

查看:162
本文介绍了请告诉我这些例子中使用的单个分号是什么。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我这两个例子中单个分号的用途。

例1:

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

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



示例2:


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;  };





我的尝试:



请告诉我这两个例子中单个分号的用途。

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

示例2:Sub(int i):超级(),mInt(i){}





< br $>
class Super {

public:

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

private:std :: string mStr; };



Class Sub:public Super {

public:

使用Super :: Super;

Sub(int i):超级(),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; };

推荐答案

您没有阅读文档(构造函数和成员初始化列表 - cppreference.com [ ^ ])你呢?
You didn't read the documentation (Constructors and member initializer lists - cppreference.com[^]) did you?


这篇关于请告诉我这些例子中使用的单个分号是什么。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆