作者freesamael (烧卖)
站内Programming
标题Re: 请问静态函数?
时间Wed Sep 12 03:51:20 2007
※ 引述《[email protected] (大改名片档)》之铭言:
: 这在书本上看到,这个程式的目的是介绍朋友类别,
: 只是我有一个疑问,为何这里的
: static void speed(int power);
: 前面要加上static?
: 这是指这是一个静态函数吗?
: 那静态函数的意义是什麽呢?
: 谢谢!
: class Spec//friend class
: {
: public:
: static void speed(int power);
: };
static member function 代表的是不必有实体物件就能操作的 member function。
也就是说,你不需要自己建立任何 Spec 的 instance,就能呼叫 Spec::speed()。
一般的 member function 的操作方法是:
Spec s; // 这就是 instance
s.func();
static member function 的操作方法是:
Spec::func();
--
Licensed under CC2.5(TW) by-sa, Samael Wang.
http://creativecommons.org/licenses/by-sa/2.5/tw/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.135.82.153