#include
"stdafx.h"
#include
"iostream.h"
class circle
{
private:
int x,y,r;
static int num;
public:
static void print(circle s);
void add();
circle(int a,int b,int c);
};
void circle::print(circle s)
{
// cout<<
"圓心:("<<x<<
","<<y<<
")"<<endl;//錯,靜態函數中不能調用非靜態數據成員
// cout<<
"半徑:"<<r<<endl;
cout<<
"靜態量:"<<num<<endl;
cout<<
"圓心:("<<s.x<<
","<<s.y<<
")"<<endl;
cout<<
"半徑:"<<s.r<<endl<<endl;
}
void circle::add()
{
num++;
}
circle::circle(int a,int b,int c)
{
x=a;
y=b;
r=c;
}
int circle::num=0;//靜態數據成員必須初始化,而且也只有這麼一種引用模式,只能寫在這裏,寫在main函數裏面也是錯的
int main(int argc, char* argv[])
{
circle p1(0,0,1);
p1.add();
p1.print(p1);//能夠像其它函數同樣引用
circle *p2=
NULL;
p2=
new circle(0,0,2);
p2->add();
circle::print(*p2);//也能夠用類的方式引用
delete p2;
p2=
NULL; return 0; }