希望达人赐教一下
class Cat
{
public:
Cat();
Cat(const Cat&);
~Cat();
int const GetAge()
{
return *itsAge;
}
int const GetWeight()
{
return *itsWeight;
}
void SetAge(int age)
{
*itsAge=age;
}
private:
int *itsAge;
int *itsWeight;
};
Cat::Cat()
{
itsAge=new int;
itsWeight=new int;
*itsAge=5;
*itsWeight=3;
}
Cat::Cat(const Cat & rhs)
{
itsAge=new int;
itsWeight=new int;
*itsAge=rhs.GetAge();
*itsWeight=*(rhs.itsWeight);
}
Cat::~Cat()
{
delete itsAge;
itsAge=0;
delete itsWeight;
itsWeight=0;
}
void main()
{
Cat cat;
cout<<cat.GetAge()<<endl;
cat.SetAge(89);
cout<<cat.GetAge()<<endl;
// cat boot(cat);
// cout<<boot.GetAge()<<endl;
cat.SetAge(98);
// cout<<cat.GetAge()<<endl;
// cout<<boot.GetAge()<<endl;
}
vc++6.0编译
:\Program Files\Microsoft Visual Studio\MyProjects\textOverLoad\overLoad.cpp(85) : error C2662: 'GetAge' : cannot convert 'this' pointer from 'const class Cat' to 'class Cat &'
Conversion loses qualifiers
[此贴子已经被作者于2007-7-22 22:31:43编辑过]