}
voidmain()
{
CPointpt;
pt.Set(10,20);
pt.Print();
}
问题一:
以上程序编译能通过吗?
如果不能,原因是什么?
能通过编译。
问题二:
以上程序的运行结构是否正确,如果不正确,分析为什么,如何改正?
结果不正确,因为Set函数中的形参与类中的相同产生错误,改为voidCPoint:
:
Set(intm,intn)。
2.理解下面的程序并运行,然后回答后面的问题。
#include
classCPerson
{
public:
voidPrint();
private:
CPerson();
private:
intage;
char*name;
};
CPerson:
:
CPerson()
{
}
voidCPerson:
:
Print()
{
cout<<"name="<}
voidmain()
{
CPersonps(23,"张三");
ps.Print();
}
问题一:
以上程序存在三个错误,在不改变主函数内容的前提下,试改正该程序。
#include
#include
usingnamespacestd;
class