博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c ++类成员函数_仅使用C ++创建具有公共数据成员的类
阅读量:2532 次
发布时间:2019-05-11

本文共 1339 字,大约阅读时间需要 4 分钟。

c ++类成员函数

Let’s understand

让我们来了解

  1. What is data member?

    什么是数据成员?

    Any variable declared inside the class in known as 'data member' of the class.

    在类内部声明的任何变量,称为类的“数据成员”。

  2. What is public data member?

    什么是公共数据成员?

    A variable declared inside the 'public' section of the class is known as 'public data member'.

    在类的“公共”部分内声明的变量称为“公共数据成员”。

In this example, we are going to create a class with the pubic data members, a public data member can be accessed outside of the class with object name, and public data member’s value can be set and get outside of the class with its object name.

在此示例中,我们将使用公共数据成员创建一个类,可以使用对象名称在该类之外访问公共数据成员,并且可以设置公共数据成员的值并使用其对象名在该类之外。

So, here in this example,

因此,在此示例中,

  • Number is the class name.

    数字是班级名称。

  • num is an integer data member, which is declared in the public section of the class - so it is a public data member.

    num是一个整数数据成员,它在该类的public部分中声明-因此它是一个公共数据成员。

  • In the main, N is the object to class Number.

    基本上, N是Number类的对象。

  • N.num is using to set and then get the value.

    N.num用于设置然后获取值。

Example:

例:

#include 
using namespace std;//class declaration class Number{
public: int num;};//Main function int main(){
//creating object Number N; //setting value to public data member N.num = 100; //printing value cout<<"value of N.num = "<
<

Output

输出量

value of N.num = 100

翻译自:

c ++类成员函数

转载地址:http://bbazd.baihongyu.com/

你可能感兴趣的文章
程序员最想得到的十大证件,你最想得到哪个?
查看>>
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>
IOS内存管理
查看>>
middle
查看>>
[Bzoj1009][HNOI2008]GT考试(动态规划)
查看>>