请问一下C++中 类的继承,我按照教科书里面的编程上机实验 但是却无法修正提示的错误,求帮忙!!
#include<iostream>using namespace std;
class TVehicle
{
private:
int m_wheels;
float m_weight;
public:
void initialize(int wheels,float weight);
int GetWheels(void){return m_wheels;}
float GetWeight(void){return m_weight;}
};
TVehicle::initialize (int wheels,float weight)
{
m_wheels = wheels;
m_weight = weight;
}
int main(void)
{
TVehicle.A;
A.initialize(4,6);
cout<<"交通工具有几个轮子"<<A.GetWheels()<<endl;
cout<<"交通工具有多重"<<A.GetWeight()<<endl;
getchar();
}
编译之后提示:::
1>正在编译...
1>paisheng.cpp
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(17) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(17) : error C2556: “int TVehicle::initialize(int,float)”: 重载函数与“void TVehicle::initialize(int,float)”只是在返回类型上不同
1> d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(10) : 参见“TVehicle::initialize”的声明
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(17) : error C2371: “TVehicle::initialize”: 重定义;不同的基类型
1> d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(10) : 参见“TVehicle::initialize”的声明
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(21) : error C2143: 语法错误 : 缺少“;”(在“.”的前面)
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(21) : error C2059: 语法错误 : “.”
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(26) : error C2065: “A”: 未声明的标识符
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(26) : error C2228: “.initialize”的左边必须有类/结构/联合
1> 类型是“'unknown-type'”
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(27) : error C2065: “A”: 未声明的标识符
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(27) : error C2228: “.GetWheels”的左边必须有类/结构/联合
1> 类型是“'unknown-type'”
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(28) : error C2065: “A”: 未声明的标识符
1>d:\my documents\documents\visual studio 2008\projects\派生类继承\paisheng\paisheng.cpp(28) : error C2228: “.GetWeight”的左边必须有类/结构/联合
1> 类型是“'unknown-type'”
1>生成日志保存在“file://d:\My Documents\Documents\Visual Studio 2008\Projects\派生类继承\paisheng\Debug\BuildLog.htm”
1>paisheng - 11 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========