作者starmovie (盗族)
看板C_and_CPP
标题[问题]有关class的小问题(c++)
时间Sun Feb 15 22:13:17 2009
以下是原本的程式码
#include <iostream>
#include <cstdlib>
using namespace std;
class CWin
{
public:
char id;
int width,height;
int area()
{
return width*height;
}
void show_area(void)
{
cout << "window " << id << ", area=" << area() << endl;
}
void set_data(char i,int w,int h)
{
id=i;
width=w;
height=h;
}
void set_data(char i)
{
id=i;
}
void set_data(int w,int h)
{
width=w;
height=h;
}
};
int main(void)
{
CWin win1,win2;
win1.set_data('A',50,40);
win2.set_data('B');
win2.set_data(80,120);
win1.show_area();
win2.show_area();
system("pause");
return 0;
}
现在想把id,width,height的成员存取属性改成private
然後也把set_data()改成friend函数,可是我想很久想不出来怎麽改= =
麻烦各位大大指点一下= =
谢谢!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 114.44.117.53