请告诉我这些例子中单结肠的用途。 [英] Please tell me what the single colon is used for in these examples.

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

问题描述

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

例1:



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



例2:



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



我尝试过:



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

例1:



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



例2:



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

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) {}

推荐答案

它将派生类构造函数与基类构造函数分开从成员初始化。一般格式为:
It is separating the derived class constructor from the base class constructor and from member initializations. The general format is :
DerivedClass( derived_args, base_arguments )
    : BaseClass( base_arguments )
    , m_Member1( initial_value1 )
    , m_Member2( initial_value2 )
{
   // constructor implementation
}

I建议在C ++参考站点阅读本教程:类(I) - C ++教程 [ ^ ]

I recommend reading this tutorial at the C++ reference site: Classes (I) - C++ Tutorials[^]


请研究 C ++语言参考| Microsoft Docs [ ^ ]您将比在此处发布基本问题更快地学习。
Please study C++ Language Reference | Microsoft Docs[^] you will learn much faster than by posting basic questions here.


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

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