日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c ++类成员函数_仅使用C ++创建具有公共数据成员的类

發布時間:2023/12/1 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c ++类成员函数_仅使用C ++创建具有公共数据成员的类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c ++類成員函數

Let’s understand

讓我們來了解

  • What is data member?

    什么是數據成員?

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

    在類內部聲明的任何變量,稱為類的“數據成員”。

  • 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 <iostream> using namespace std;//class declaration class Number{public:int num; };//Main function int main() {//creating objectNumber N;//setting value to public data member N.num = 100;//printing valuecout<<"value of N.num = "<<N.num<<endl;return 0; }

    Output

    輸出量

    value of N.num = 100

    翻譯自: https://www.includehelp.com/cpp-programs/create-a-class-with-public-data-members-only-in-cpp.aspx

    c ++類成員函數

    總結

    以上是生活随笔為你收集整理的c ++类成员函数_仅使用C ++创建具有公共数据成员的类的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。