|
lesson5-4cat.hpp文件的内容如下:
#include <iostream>
using namespace std;
class Cat
{
public:
Cat(int initialAge);
~Cat();
int GetAge(){return itsAge;}
void SetAge(int age){itsAge=age;}
void Meow(){cout<<"Meow.\n";}
private:
int itsAge;
};
lesson5-4.cpp文件的内容如下:
#include "lesson5-4cat.hpp"
Cat::Cat(int initialAge)
{
itsAge=initialAge;
}
Cat::~Cat()
{
}
int main()
{
Cat Frisky(5);
Frisky.Meow();
cout<<"Frisky is a cat who is ";
cout<<Frisky.GetAge()<<" years old.\n"
Frisky.Meow();
Frisky.SetAge(7);
cout<<"Now Frisky is ";
cout<<Frisky.GetAge()<<" years old.\n";
}
在g++ -Wall -g lesson5-4.cpp -o lesson5-4的过程中出险如下的错误,不知道如何解决
in file included from lesson5-4.cpp:1:
lesson5-4cat.hpp:13:3:warning:no new line at end of file
lesson5-4.cpp: in function ' int main( )':
lesson5-4.cpp:16: parse error before '.' token
building completed....unsuccessful. |
|