امیدوارم بااین کد مشکلت حل شه من تو محیط داس کامپایل کردم ولی یه وارنینگ داره کار باusing namespace std; رو بلد نبودم پاک کردم فکر کنم مشکلی پیش نیاد
کد:
// LISTING OF CAT
#include <iostream.h>
#include<conio.h>
class Cat
{
public:
Cat();
Cat(const Cat &);
~Cat();
int GetAge() { return *itsAge; }
int GetWidth() { return *itsWidth; }
void SetAge(int age) { *itsAge = age; }
private:
int * itsWidth;
int * itsAge;
};
Cat::Cat()
{
itsAge = new int;
itsWidth = new int;
*itsAge = 5;
*itsWidth = 9;
}
Cat::Cat(const Cat & rHs)
{
itsAge = new int;
itsWidth = new int;
*itsAge = rHs.GetAge(); //???
*itsWidth = *(rHs.itsWidth);
}
Cat::~Cat()
{
delete itsAge;
itsAge = 0;
delete itsWidth;
itsWidth = 0;
}
int main()
{
Cat frisky;
cout <<"frisky is "<<frisky.GetAge()<<endl;
cout <<"SETTIIS....";
frisky.SetAge(6);
Cat boots(frisky);
cout <<"boots is "<<boots.GetAge()<<endl;
cout <<"and frisky is " <<frisky.GetAge() <<endl;
getch();
return 0;
}