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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c中将数组传递给子函数_在C ++中将对象传递给Non-Member函数

發(fā)布時(shí)間:2023/12/1 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c中将数组传递给子函数_在C ++中将对象传递给Non-Member函数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

c中將數(shù)組傳遞給子函數(shù)

Here, we have to define a Non-Member Function, in which we have to pass an Object to the class in C++ programming language.

在這里,我們必須定義一個(gè)非成員函數(shù),其中必須將一個(gè)Object傳遞給C ++編程語言的類。

What we are doing in this example?

在此示例中我們正在做什么?

  • We declared a class named Number that has a private data member named num.

    我們聲明了一個(gè)名為Number的類,該類具有一個(gè)名為num的私有數(shù)據(jù)成員。

  • We define a Non Member function named myFunction(), that will take two parameters 1) object to class Number and 2) an integer variable number.

    我們定義了一個(gè)名為myFunction()的非成員函數(shù),該函數(shù)將使用兩個(gè)參數(shù):1)對象為Number類,以及2)一個(gè)整數(shù)變量number 。

Using the example, We have to supply a number (from the main() function) to the class's data member using a Non-Member Function.

使用示例,我們必須使用非成員函數(shù)為類的數(shù)據(jù)成員提供一個(gè)數(shù)字(來自main()函數(shù))。

Program:

程序:

#include <iostream> using namespace std;class Number {private:int num;public:void setNum(int n){num = n;}int getNum(void){return num;} };//a non member function void myFunction(class Number N, int number) {//calling setter function and asigning the number N.setNum(number) ;//calling getter function and printing the value cout<<"The value is: " << N.getNum() << endl; }//Main function int main() {//local variable of the main int num;//object to Number class Number objN;num = 10;//supplying this 'num' to the class by passing //the name to the class in a non memberfunctionmyFunction (objN, num);return 0; }

Output

輸出量

The value is: 10

翻譯自: https://www.includehelp.com/cpp-programs/passing-an-object-to-a-non-member-function-in-cpp.aspx

c中將數(shù)組傳遞給子函數(shù)

總結(jié)

以上是生活随笔為你收集整理的c中将数组传递给子函数_在C ++中将对象传递给Non-Member函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。