【发布时间】:2014-03-19 04:49:16
【问题描述】:
我收到了
expected class-name before '{' token
在下面的代码中
saltwaterfish.h 头文件:
#ifndef SALTWATERFISH_H
#define SALTWATERFISH_H
class saltwaterfish: public fish
{
public:
saltwaterfish();
float GetUnitPrice();
float GetWeight();
};
#endif // SALTWATERFISH_H
这是定义头文件的正确方法吗
“咸水鱼是鱼的子类”?
我在 saltwaterfish.cpp 中唯一拥有的是
#include "fish.h"
#include "saltwaterfish.h"
fish.cpp 类:
#include "fish.h"
#include <iostream>
#include "freshwaterfish.h"
#include "saltwaterfish.h"
using namespace std;
fish::fish()
{
};
float fish::CalculatePrice()
{
return GetUnitPrice()*GetWeight();
}
float fish::GetUnitPrice()
{
return 1.0;
}
float fish::GetWeight()
{
return 1.0;
}
【问题讨论】:
-
你能在这里贴出fish类的代码吗?可能你在fish类的末尾缺少
};。 -
您是否收到
saltwaterfish.cpp的此错误? -
去掉
fish构造函数主体后的分号。 -
你的头文件不是独立的。那时你的头文件没有定义fish。
标签: c++ inheritance