1.用的是visual c++软件 c++语言编译的
2.Bike是个派生类,Bike的基类是Vehicle,Vehicle的基类是Transportation,在编译Bike.cpp文件时,一直出现如下错误:error C2653: 'Bike' : is not a class or namespace name 。估计是头文件的问题,请问怎么解决?
3.Vehicle.h Vehicle.cpp Bike.h Bike.cpp的文件代码如
Vehicle.h文件代码
//车类.h
#include <iostream>
using namespace std;
#ifndef MENU
#define MENU
#include "Transportation.h"
//6.定义虚基类
class Vehicle:virtual public Transportation
{
public:
int maxspeed;
Vehicle();
Vehicle(string na,int max);
void show1();
void enjoy();
};
#endif
Vehicle.cpp文件代码
//车类.cpp
#include <string>
using namespace std;
#include "Vehicle.h"
Vehicle::Vehicle(string na,int max):Transportation(na)
{
name=na;
maxspeed=max;
}
void Vehicle::show1()
{
cout<<"\t 名字是:"<<name<<endl;
cout<<"\t 最大速度是:"<<maxspeed<<"km/h"<<endl;
}
//7
void Vehicle::enjoy()
{
cout<<"\t 建立车类交通工具"<<endl;
};
Bike.cpp 文件
//自行车类
#include "Bike.h"
//3.静态数据成员初始化,不赋予初值默认为0
float Bike::sum;
int Bike::count;
//4.Bike派生类的构造函数
Bike::Bike(string na,int max,int pr):Vehicle(na,max)
{
price=pr;
}
void Bike::total()
{
//3.累计自行车的总价格
sum+=price;
//3.累计共算入统计的自行车数
count++;
}
//3.静态成员函数定义
float Bike::average()
{
return(sum/count);
};
//7
void Bike::enjoy()
{
cout<<"\t自行车属于车类交通工具"<<endl;
cout<<"\t自行车的优点是环保"<<endl;
};
void Bike::show3()
{
cout<<"\t名字是:"<<name<<endl;
cout<<"\t最大速度是:"<<"km/h"<<endl;
cout<<"\t价格为:"<<price<<"元"<<endl;
}
Bike.h文件
//自行车类.h
#include <iostream>
#include "Vehicle.h"
using namespace std;
#include <string>
class Bike::public Vehicle
{
public:
int price;
Bike(string na,int max,int pr);
void show3();
void enjoy();
void total(); //?
//3.静态数据成员,sum累计自行车价格
static float sum;
//3.静态数据成员,count累计自行车数量
static int count;
//3.声明静态成员函数
static float average();
};
你好,我是有问必答小助手。为了技术专家团更好地为您解答问题,烦请您补充下(1)问题背景详情,(2)您想解决的具体问题,(3)问题相关图片。便于技术专家团更好地理解问题,并给出解决方案。
您可以点击问题下方的【编辑】,进行补充修改问题。