#include
"stdafx.h"
#include
"iostream.h"
class circle
{
private:
int x,y,r;
const int z;
public:
void print();
void circle::print()
const;
circle(int a,int b,int c);
circle(int a,int b,int c,int d);//函數聲明中初始化列表不用帶
};
void circle::print()
{
cout<<
"圓心:("<<x<<
","<<y<<
")"<<endl;
cout<<
"半徑:"<<r<<endl;
}
void circle::print()
const//重載了一個常量print函數
{
cout<<
"圓心:("<<x<<
","<<y<<
")"<<endl;
cout<<
"半徑:"<<r<<endl;
cout<<
"常量數據成員爲:"<<z<<endl;
}
// circle::circle(int a,int b,int c)//錯,會提示常量成員z沒有初始化
// {
// x=a;
// y=b;
// r=c;
// }
circle::circle(int a,int b,int c,int d):z(d)
{
x=a;
y=b;
r=c;
}
int main(int argc, char* argv[])
{
circle p1(0,0,1,3);
p1.print();
const circle p2(0,0,2,3); p2.print();//由於這裏重載了一個常函數print return 0; }