close
Classes can contain data and functions. These functions are referred to as "member functions."
Any nonstatic function declared inside a class declaration is considered a member function and is called using the member-selection operators (. and –>).
When calling member functions from other member functions of the same class, the object and member-selection operator can be omitted.
(member function間的呼叫 , 可以不用透過member-selection operators .)
#include <iostream>
using namespace std;
class Point
{
public:
short x()
{
return _x;
}
short y()
{
return _y;
}
void Show()
{
cout << x() << ", " << y() << "\n";
}
private:
short _x, _y;
};
int main()
{
Point pt;
pt.Show();
}
These calls implicitly mean this->x() and this->y() .
全站熱搜