frend function in class
有一個程式
內容是說明將一個class內的function設定為friend
只是..
我看不太懂這樣做的目的為何
因為既然設定為friend
那是不是就可以呼叫裡面的資料
那該怎麼呼叫呢
我把原始程式貼上來
煩請大大賜教
#include <iostream>
using namespace std;
class Spec
{
private:
void speed(int power);
};
class Car{
private:
friend void Spec::speed(int); //friend function of class
public:
int num;
double gas;
//friend void Spec::speed(int); //friend function of class
};
class car1:public Car
{
};
void Spec::speed(int power)
{
int motive=power;
cout<<"--March--\n"<<"傳入為"<<motive<<endl;
}
int main()
{
Spec pow;
Car March;
March.num=200;
March.gas=20.0;
pow.speed(300);
cout<<"號碼為"<<March.num;
cout<<"Gas為"<<March.gas<<endl;
system("PAUSE");
return 0;}
--
┌─────◆KKCITY◆─────┐▇─┐ 優質連線服務隆/重/豋/場!!
│ bbs.kkcity.com.tw │┴ └─▇ KKADSL 帶你環遊全世界
└──《From:140.109.139.90 》──┘ KKADSL ┴ http://adsl.kkcity.com.tw
--
Programming 近期熱門文章
PTT數位生活區 即時熱門文章