}
int main()
{
print();
return 0;
}
**********************************************************************************
#include
using namespace std;
class A
{
private:
const int x;
const int y;
int m;
int &rm;
int z;
public:
A(int x1,int y1,int
z1):x(x1),y(y1),rm(m),z(z1)
{
}
void print()
{
cout<<"x="<
cout<<"y="< cout<<"z="< }
};
int main()
{
A a(10,20,30);
a.print();
A a1(50,60,70);
a1.print();
return 0;
}
***********************************************************************
#include
using namespace std;
class A
{
public:
mutable int x;
int y;
int z;
public:
A()
{
cout<<"无参构造函数"< }
A(int x1,int y1,int z1)
{
x=x1;
y=y1;
z=z1;
cout<<"有参构造函数"< }
void set(int x1)const
{
x=x1;
}
void print()const
{
cout<<"x="< cout<<"y="< cout<<"z="< cout<<"const函数"<
}
void print()
{
cout<<"x="< cout<<"y="< cout<<"z="< cout<<"非const函数"< }
};
int main()
{
const A a(100,200,300);
a.x=800;
a.set(1000);
//a.set(700,800,900);
a.print();
A a1(1000,2000,3000);
a1.print();
return 0;
}
********************************************************************
#include
using namespace std;
class A
{
public:
static int x;
int y;
int z;
void print()
{
cout< printstatic();
}
static void printstatic()
{
cout<
}
};
int A::x=0;
int main()
{
A a;
A a1;
a.x=100;
cout<<"a1.x="<
a1.x=200;
cout<<"a.x="<
cout<<"&a.x="<<&a.x<
cout<<"&a1.x="<<&a1.x<
cout<<"A::x="<
cout<<"&A::x="<<&A::x< A::printstatic();
return 0;
}
**********************************************************************
#include
using namespace std;
class student
{
public:
int id;
string name;
int math;
public:
student()
{
id=0;
math=0;
name="";
cout<<"无参构造函数"<
}
student(int id1,string
name1,int
math1)
{
id=id1;
name=name1;
if(math1>=0)
{
math=math1;
}
else
{
math=0;
cout<<"数据错误"< }
cout< }
void set(int id1,string name1,int
math1)
{
id=id1;
name=name1;
if(math1>=0)
{
math=math1;
}
else
{
math=0;
cout<<"数据输入错误,请重新输入"< }
}
void print()
{
cout<<"this="< cout<<"id:"<
cout<<"姓名:"< cout<<"成绩:"<
};
int main()
{
// student *p=new student;
// p->set(1,"aa",100);
// p->print();
// delete p;
student *p1=new student[3];
p1[0].set(1,"aa",100);
p1[1].set(2,"bb",60);
p1[0].print();
p1[1].print();
delete []p1;
// p->set(1,"aa",100);
// p->print();
// delete p;
/* student *p;
student stu1;
p=&stu1;
p->id=1;
p->name="李呈";
p->math=100;
p->print();
student &rstu1=stu1;
rstu1.id=2;
rstu1.print();
*/
// student stu1(1,"张三",100);
// student stu2(2,"aa",60);
// stu1.id=1;
// stu1.name="张三";
// student stu3(3,"李四",80);
// stu2.id=2;
// stu2.name="李四";
// stu1.print();
// stu2.print();
// cout<<"&stu1="<<&stu1<
/* cout<<"&stu1.id="<<&stu1.idi< cout<<"&stu1.name="<<&stu1.name<
cout<<"&stu1.math="<<&stu1.math<
*/
// cout<<"&stu2="<<&stu2</* cout<<"&stu2.id="<<&stu2.id< cout<<"&stu2.name="<<&stu2.name<
cout<<"&stu2.math="<<&stu2.math< return 0;
}
阅读(634) | 评论(0) | 转发(0) |