主题:求求各位高手帮我看看以下程序有什么错?如何改
(1)使用静态成员函数
#include<iostream.h>
#include<string.h>
class person{
public:
char m_strName[20];
long m_ID;
public:
person(char*strName,long ID){strcpy(m_strName,strName);m_ID=ID}
static long GetID() { return m_ID;}
};
void main()
{
person person1("LiuJun",1101640524);
cout<<"ID="<<person∷GetID()<<'\n';
}
(2)派生类的构造函数调用基类的构造函数据
#include<iostream.h>
class point
{
protected:
int x,y;
public:
point(int a ,int b) { x=a;y=b }
int getX() { return x; }
int getY() { return y; }
};
class circle : public point
{
protected;
int radius;
public:
circle(int a=0, int b=0, int r=0){radius=r; }
int getRadius() { return radius; }
};
void main()
{
circle c(100,150,200);
cout<<"x="<<c.getX()<<" ,y="<<c.getY()<<" ,radius="<<c.getRadius()<<end;
}
(3)关于常对象和常对象成员
#include<iostream.h>
class sample
{
private:
int n;
public:
sample(int x) {n=x;}
void setValue(int x) { n=x; }
void Display() { cout<<"n="<<n<<entl;}
};
void main()
{
const Sample a(100);
a.SetValue(0);
a.Dispiay();
}
#include<iostream.h>
#include<string.h>
class person{
public:
char m_strName[20];
long m_ID;
public:
person(char*strName,long ID){strcpy(m_strName,strName);m_ID=ID}
static long GetID() { return m_ID;}
};
void main()
{
person person1("LiuJun",1101640524);
cout<<"ID="<<person∷GetID()<<'\n';
}
(2)派生类的构造函数调用基类的构造函数据
#include<iostream.h>
class point
{
protected:
int x,y;
public:
point(int a ,int b) { x=a;y=b }
int getX() { return x; }
int getY() { return y; }
};
class circle : public point
{
protected;
int radius;
public:
circle(int a=0, int b=0, int r=0){radius=r; }
int getRadius() { return radius; }
};
void main()
{
circle c(100,150,200);
cout<<"x="<<c.getX()<<" ,y="<<c.getY()<<" ,radius="<<c.getRadius()<<end;
}
(3)关于常对象和常对象成员
#include<iostream.h>
class sample
{
private:
int n;
public:
sample(int x) {n=x;}
void setValue(int x) { n=x; }
void Display() { cout<<"n="<<n<<entl;}
};
void main()
{
const Sample a(100);
a.SetValue(0);
a.Dispiay();
}