#include <iostream >
using namespace std;
class Cat
{ public:
int GetAge();
void SetAge(int age);
void Meow();
protected:
int itsAge;
};
int Cat::GetAge(){return itsAge;}
void Cat::SetAge(int age){itsAge=age;}
void Cat::Meow(){cout<<"Meow...\n";}
int _tmain(int argc, _TCHAR* argv[])
{
Cat frisky;
frisky.SetAge(5);
frisky.Meow();
cout <<"frisky is a cat who is "<<frisky.GetAge()<<" years old.\n";
frisky.Meow();
return 0;
}
怎么放到C++08中的头文件、源文件中去啊,各自文件要加什么东西?
高手指点一下
头文件:
#ifndef CAT_H
#define CAT_H
#include <iostream >
using namespace std;
class Cat
{ public:
int GetAge();
void SetAge(int age);
void Meow();
protected:
int itsAge;
};
#endif
资源文件:
Cat.cpp
#include "Cat.h"
int Cat::GetAge(){return itsAge;}
void Cat::SetAge(int age){itsAge=age;}
void Cat::Meow(){cout<<"Meow...\n";}
main.cpp
#include "Cat.h"
int _tmain(int argc, _TCHAR* argv[])
{
Cat frisky;
frisky.SetAge(5);
frisky.Meow();
cout <<"frisky is a cat who is "<<frisky.GetAge()<<" years old.\n";
frisky.Meow();
return 0;
}
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息