LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1061|回复: 2

C++关于类的问题,请指教

[复制链接]
发表于 2004-1-30 14:40:17 | 显示全部楼层 |阅读模式
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.
发表于 2004-1-30 18:57:36 | 显示全部楼层
lesson5-4cat.hpp:13:3:warning:no new line at end of file
文件结尾处理一下,比如用vim在最后一行后面加一行
lesson5-4.cpp:16: parse error before '.' token
15缺少结尾的分号
发表于 2004-2-8 16:24:06 | 显示全部楼层

这一行少分号

cout<<Frisky.GetAge()<<" years old.\n"
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表