课堂帮助 [英] Class Help

查看:95
本文介绍了课堂帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我有一个差不多已完成的程序,但是我收到编译错误

两行:317& 319.我认为主要的错误与卡车类有关。


我是新手并继续查看代码,但似乎无法看到

错误。我不理解很多花哨的东西,所以如果你能保留它

对我来说简单!!!!感谢任何帮助!


这是代码:


#include< iostream>

#include < string>


使用命名空间std;


// ================ ===============

//人员声明类

// =========== ====================

班级人员

{

public:

Person();

Person(string theName);

Person(const Person& theObject);

string getName()const;

void setName(string newName);

Person& operator =(const Person& rtSide);

friend istream&运算符>>(istream& inStream,

Person& personObject);

friend ostream& operator<<(ostream& outStream,

const Person& personObject);

private:

string name;

};

// ================================
//车辆类声明

// ============================= ===

级车辆

{

公共:

车辆();

Vehicle(string m,int cyl,Person p);

Vehicle(const Vehicle& theObject);

string getManufacturer()const;

int getCylinders()const;

Person getOwner()const;

void setManufacturer(string maker);

void setCylinders(int cylinders) );

void setOwner(Person p);


void output();

//输出数据的成员适当标记的课程


车辆和车辆operator =(const Vehicle& rtSide);

private:

string manufacturer;

int numCylinders;

Person老板;

};

// ============================ ===

//卡车类声明

// ======================= ========

级卡车:公共车辆

{

公共:

卡车( );

卡车(字符串m,int cyl,Person p,双重载荷,int tow);

卡车(const Truck& theObject);

double getLoadCapacity()const;

int getTowingCapacity()const;

void setLoadCapacity(double newLoad);

void setTowingCapacity(int newTowing );


无效输出();

//输出适当标记的数据成员。


卡车& operator =(const Truck& rtSide);

private:

double loadCapacity;

int towingCapacity;

} ;

// ===================

//主要功能

// ===================

int main()

{

//

//变量声明

//

string ownerName;

string manufacturerName;

int numCyl;

双重装载;

int towingCapacity;


cout<< endl;

cout<< 测试卡车和人员类...... << endl;

cout<< endl;


cout<< 首先制造3辆卡车...... << endl;

cout<< 卡车A ...... << endl;

cout<< 输入所有者的姓名:;

cin>> ownerName;

cout<< 输入柱面数:;

cin>> numCyl;

cout<< 输入制造商的名称:;

cin>> manufacturerName;

cout<< 输入负载容量:;

cin>>加载;

cout<< 输入牵引能力:;

cin>> towingCapacity;


卡车A;

人员A;

cout<< 使用mutator功能设置车主和卡车

A ... << endl;

ownerA.setName(ownerName);

truckA.setOwner(ownerA);

truckA.setManufacturer(manufacturerName);

truckA.setCylinders(numCyl);

truckA.setLoadCapacity(load);

truckA.setTowingCapacity(towingCapacity);


cout<< endl;

cout<< 输入卡车B的数据...... << endl;

cout<< 输入所有者的姓名:;

cin>> ownerName;

cout<< 输入柱面数:;

cin>> numCyl;

cout<< 输入制造商的名称:;

cin>> manufacturerName;

cout<< 输入负载容量:;

cin>>加载;

cout<< 输入牵引能力:;

cin>> towingCapacity;

cout<< endl;


cout<< 使用带有5个参数的构造函数来创建Truck B ...

<< endl;

Person ownerB(ownerName);

卡车truckB(manufacturerName,numCyl,ownerB,load,towingCapacity);


cout<< 使用复制构造函数创建卡车C作为

卡车A ......的副本。 << endl;

卡车C(卡车A);


cout<< 使用存取器功能来打印卡车信息...... <<

endl;

cout<< endl;

cout<< 卡车A ...... << endl;

cout<< 所有者: << truckA.getOwner()<< endl;

cout<< 制造商: << truckA.getManufacturer()<< endl;

cout<< 气缸数: << truckA.getCylinders()<< endl;

cout<< 负载容量: << truckA.getLoadCapacity()<< endl;

cout<< 牵引能力: << truckA.getTowingCapacity()<< endl;

cout<< endl;


cout<< Truck B ...... << endl;

cout<< 所有者: << truckB.getOwner()<< endl;

cout<< 制造商: << truckB.getManufacturer()<< endl;

cout<< 气缸数: << truckB.getCylinders()<< endl;

cout<< 负载容量: << truckB.getLoadCapacity()<< endl;

cout<< 牵引能力: << truckB.getTowingCapacity()<< endl;

cout<< endl;


cout<< 卡车C ...... << endl;

cout<< 所有者: << truckC.getOwner()<< endl;

cout<< 制造商: << truckC.getManufacturer()<< endl;

cout<< 气缸数: << truckC.getCylinders()<< endl;

cout<< 负载容量: << truckC.getLoadCapacity()<< endl;

cout<< 牵引能力: << truckC.getTowingCapacity()<< endl;

cout<< endl;


cout<< 为Truck C输入新的所有者名称:;

人所有者C;

cin>> ownerC;

truckC.setOwner(ownerC);


cout<< 为C卡车输入新的牵引能力:;

cin>> towingCapacity;

truckC.setTowingCapacity(towingCapacity);


cout<< 为卡车B输入新的制造商:;

cin>> manufacturerName;

truckB.setManufacturer(manufacturerName);

cout<< endl<< endl;


cout<< 改变后的卡车B ...... << endl;

truckB.output();

cout<< endl;


cout<< 改变后的卡车C ...... << endl;

truckC.output();

cout<< endl;


cout<< 测试赋值运算符...... << endl;

cout<< 测试truckA = truckB << endl;

cout<<结束;


truckA = truckB;


cout<< 按任意字母查看结果...;

cin>> ownerName;

cout<< endl;


cout<< 卡车A << endl;

truckA.output();

cout<< endl;


cout<< 卡车B << endl;

truckB.output();

cout<< endl;


cout<< 做出一些改变...... << endl;

cout<< 输入卡车A的负载能力:;

cin>>加载;

truckA.setLoadCapacity(加载);

cout<< 将卡车A的所有者设置为Bo。 << endl;

truckA.setOwner(人(Bo));

cout<< 将卡车B的所有者改为卡车C的ower << endl;

ownerB = ownerC;

truckB.setOwner(ownerB);

cout<< 为卡车B输入新的汽缸数量:;

cin>> numCyl;

truckB.setCylinders(numCyl);

cout<< endl;


cout<< 改变之后...... << endl;


cout<< 卡车A << endl;

truckA.output();

cout<< endl;


cout<< 卡车B << endl;

truckB.output();


cout<< endl<< 结束...... << endl;


返回0;

}


// ========== ======================

//车辆类别定义

// ===== ===========================

车辆::车辆()

{

}

车辆::车辆(字符串m,int cyl,Person p):制造商(m),

numCylinders (cyl),车主(p)

{

}

车辆::车辆(const Vehicle& theObject)

{

manufacturer = theObject.manufacturer;

numCylinders = theObject.numCylinders;

owner = theObject.owner;

}

string Vehicle :: getManufacturer()const

{

返回制造商;

}

int Vehicle :: getCylinders()const

{

返回numCylinders;

}

Person Vehicle :: getOwner()const

{

返回所有者;

}

无效车辆: :setManufacturer(string m)

{

manufa cturer = m;

}

void Vehicle :: setCylinders(int n)

{

numCylinders = n ;

}

void Vehicle :: setOwner(Person p)

{

owner = p;

}


void Vehicle :: output()

{

cout<< 所有者: <<所有者<< endl;

cout<< 制造商: <<制造商<< endl;

cout<< 气缸数: << numCylinders<<结束;

}

车辆& Vehicle :: operator =(const Vehicle& rtSide)

{

manufacturer = rtSide.manufacturer;

numCylinders = rtSide.numCylinders;

owner = rtSide.owner;


返回* this;

}

// === ===========================

//卡车类别定义


卡车::卡车()

{

}


卡车::卡车(字符串m,int cyl,double load,int tow,Person

p):制造商(m),numCylinders(cyl),LoadCapacity(负载),

TowingCapacity(丝束),所有者(p)

{

}


卡车::卡车(常见卡车& theObject)

{

loadCapacity = theObject.loadCapacity;

towingCapcity = theObject.towingCapacity;

}


double Truck :: getLoadCapacity()const

{

return loadCapacity;

}


int Truck :: getTowingCapacity ()const

{

返回towingCapacity;

}


void Truck :: setLoadCapacity(double newLoad)

{

LoadCapacity = newLoad;

}


void Truck :: setTowingCapacity(int newTowing)

{

TowingCapacity = newTowing;

}


void Truck :: output()

{

cout<<"" Load Capaciy: "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<""""<<<< TowingCapacity<< endl;


返回* this;

}


// ==================== ==========

//人员类定义


人::人()

{

}


Person :: Person(string theName):newName(theName)

{

}


Person :: Person(const Person& theObject)

{

newName = theObject.newName;

}


string Person :: getnewName()const

{

返回newName;

}


void Person :: setnewName (字符串名称)

{

newName = n;

}


void Person ::输出()

{

cout<<" Name:"<<< newName<< endl;

return *这个;

}

Hi!

I''ve got a program that''s almost done, but I''m getting compile errors in
two lines: 317 & 319. I think the main error has to do with the Truck Class.

I''m a newbie and keep looking at the code but can''t seem to see the
error. I don''t understand a lot of the fancy stuff so if you can keep it
simple for me!!!! Any help is appreciated!

Here is the code:

#include <iostream>
#include <string>

using namespace std;

//===============================
// Declaration of Person Class
//===============================
class Person
{
public:
Person();
Person (string theName);
Person (const Person& theObject);
string getName() const;
void setName(string newName);
Person& operator=(const Person& rtSide);
friend istream& operator >>(istream& inStream,
Person& personObject);
friend ostream& operator <<(ostream& outStream,
const Person& personObject);
private:
string name;
};
//================================
// Declaration of Vehicle Class
//================================
class Vehicle
{
public:
Vehicle();
Vehicle(string m, int cyl, Person p);
Vehicle(const Vehicle& theObject);
string getManufacturer() const;
int getCylinders() const;
Person getOwner() const;
void setManufacturer(string maker);
void setCylinders(int cylinders);
void setOwner (Person p);

void output();
// Outputs the data members of the class appropriately labeled

Vehicle& operator=(const Vehicle& rtSide);
private:
string manufacturer;
int numCylinders;
Person owner;
};
//===============================
// Declaration of Truck Class
//===============================
class Truck : public Vehicle
{
public:
Truck();
Truck(string m, int cyl, Person p, double load, int tow);
Truck(const Truck& theObject);
double getLoadCapacity() const;
int getTowingCapacity() const;
void setLoadCapacity(double newLoad);
void setTowingCapacity(int newTowing);

void output();
// Outputs the data members appropriately labeled.

Truck& operator=(const Truck& rtSide);
private:
double loadCapacity;
int towingCapacity;
};
//===================
// main function
//===================
int main()
{
//
// Variable declarations
//
string ownerName;
string manufacturerName;
int numCyl;
double load;
int towingCapacity;

cout << endl;
cout << "Testing Truck and Person classes..." << endl;
cout << endl;

cout << "First create 3 trucks..." << endl;
cout << "Truck A ... " << endl;
cout << "Enter the name of the owner: ";
cin >> ownerName;
cout << "Enter the number of cylinders: ";
cin >> numCyl;
cout << "Enter the name of the manufacturer: ";
cin >> manufacturerName;
cout << "Enter the load capacity: ";
cin >> load;
cout << "Enter the towing capacity: ";
cin >> towingCapacity;

Truck truckA;
Person ownerA;
cout << "Using the mutator functions to set up the owner and truck
A..." << endl;
ownerA.setName(ownerName);
truckA.setOwner(ownerA);
truckA.setManufacturer(manufacturerName);
truckA.setCylinders(numCyl);
truckA.setLoadCapacity(load);
truckA.setTowingCapacity(towingCapacity);

cout << endl;
cout << "Enter data for Truck B ... " << endl;
cout << "Enter the name of the owner: ";
cin >> ownerName;
cout << "Enter the number of cylinders: ";
cin >> numCyl;
cout << "Enter the name of the manufacturer: ";
cin >> manufacturerName;
cout << "Enter the load capacity: ";
cin >> load;
cout << "Enter the towing capacity: ";
cin >> towingCapacity;
cout << endl;

cout << "Using the constructor with 5 arguments to create Truck B..."
<< endl;
Person ownerB(ownerName);
Truck truckB(manufacturerName, numCyl, ownerB, load, towingCapacity);

cout << "Using the copy constructor to create Truck C as a copy of
Truck A..." << endl;
Truck truckC(truckA);

cout << "Using the accessor functions to print the truck info ..." <<
endl;
cout << endl;
cout << "Truck A ..." << endl;
cout << "Owner: " << truckA.getOwner() << endl;
cout << "Manufacturer: " << truckA.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckA.getCylinders() << endl;
cout << "Load Capacity: " << truckA.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckA.getTowingCapacity() << endl;
cout << endl;

cout << "Truck B ..." << endl;
cout << "Owner: " << truckB.getOwner() << endl;
cout << "Manufacturer: " << truckB.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckB.getCylinders() << endl;
cout << "Load Capacity: " << truckB.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckB.getTowingCapacity() << endl;
cout << endl;

cout << "Truck C ..." << endl;
cout << "Owner: " << truckC.getOwner() << endl;
cout << "Manufacturer: " << truckC.getManufacturer() << endl;
cout << "Number of Cylinders: " << truckC.getCylinders() << endl;
cout << "Load Capacity: " << truckC.getLoadCapacity() << endl;
cout << "Towing Capacity: " << truckC.getTowingCapacity() << endl;
cout << endl;

cout << "Enter a new owner name for Truck C: ";
Person ownerC;
cin >> ownerC;
truckC.setOwner(ownerC);

cout << "Enter a new towing capacity for Truck C: ";
cin >> towingCapacity;
truckC.setTowingCapacity(towingCapacity);

cout << "Enter a new manufacturer for Truck B: ";
cin >> manufacturerName;
truckB.setManufacturer(manufacturerName);
cout << endl << endl;

cout << "Truck B after the changes..." << endl;
truckB.output();
cout << endl;

cout << "Truck C after the changes..." << endl;
truckC.output();
cout << endl;

cout << "Testing the assignment operators..." << endl;
cout << "Testing truckA = truckB" << endl;
cout << endl;

truckA = truckB;

cout << "Press any letter to see the results...";
cin >> ownerName;
cout << endl;

cout << "Truck A " << endl;
truckA.output();
cout << endl;

cout << "Truck B" << endl;
truckB.output();
cout << endl;

cout << "Making some changes..." << endl;
cout << "Enter a load capacity for truck A: ";
cin >> load;
truckA.setLoadCapacity(load);
cout << "Setting the owner of truck A to Bo" << endl;
truckA.setOwner(Person ("Bo"));
cout << "Changing owner of truck B to the ower of truck C" << endl;
ownerB = ownerC;
truckB.setOwner(ownerB);
cout << "Enter a new number of cylinders for truck B: ";
cin >> numCyl;
truckB.setCylinders(numCyl);
cout << endl;

cout << "After the changes ..." << endl;

cout << "Truck A " << endl;
truckA.output();
cout << endl;

cout << "Truck B" << endl;
truckB.output();

cout << endl << "The end..." << endl;

return 0;
}

//================================
// Vehicle Class Definitions
//================================

Vehicle::Vehicle()
{
}
Vehicle::Vehicle (string m, int cyl, Person p):manufacturer(m),
numCylinders(cyl), owner(p)
{
}
Vehicle::Vehicle(const Vehicle& theObject)
{
manufacturer = theObject.manufacturer;
numCylinders = theObject.numCylinders;
owner = theObject.owner;
}
string Vehicle::getManufacturer() const
{
return manufacturer;
}
int Vehicle::getCylinders() const
{
return numCylinders;
}
Person Vehicle::getOwner() const
{
return owner;
}
void Vehicle::setManufacturer (string m)
{
manufacturer = m;
}
void Vehicle::setCylinders(int n)
{
numCylinders = n;
}
void Vehicle::setOwner(Person p)
{
owner = p;
}

void Vehicle::output()
{
cout << "Owner: " << owner << endl;
cout << "Manufacturer: " << manufacturer << endl;
cout << "Number of Cylinders: " << numCylinders << endl;
}
Vehicle& Vehicle::operator=(const Vehicle& rtSide)
{
manufacturer = rtSide.manufacturer;
numCylinders = rtSide.numCylinders;
owner = rtSide.owner;

return *this;
}
//==============================
// Truck Class Definitions

Truck::Truck()
{
}

Truck::Truck(string m, int cyl, double load, int tow, Person
p):manufacturer(m), numCylinders(cyl), LoadCapacity(load),
TowingCapacity(tow), owner(p)
{
}

Truck::Truck(const Truck& theObject)
{
loadCapacity = theObject.loadCapacity;
towingCapcity = theObject.towingCapacity;
}

double Truck::getLoadCapacity()const
{
return loadCapacity;
}

int Truck::getTowingCapacity()const
{
return towingCapacity;
}

void Truck::setLoadCapacity(double newLoad)
{
LoadCapacity=newLoad;
}

void Truck::setTowingCapacity(int newTowing)
{
TowingCapacity=newTowing;
}

void Truck::output()
{
cout<<"Load Capaciy:"<<LoadCapacity<<endl;
cout<<"Tow Capacity:"<<TowingCapacity<<endl;

return *this;
}

//==============================
// Person Class Definitions

Person::Person()
{
}

Person::Person(string theName):newName(theName)
{

}

Person::Person(const Person& theObject)
{
newName=theObject.newName;
}

string Person::getnewName()const
{
return newName;
}

void Person::setnewName(string theName)
{
newName=n;
}

void Person::output()
{
cout<<"Name:"<<newName<<endl;
return *this;
}

推荐答案

DrNoose写道:
DrNoose wrote:
我有一个程序这几乎已经完成,但是我在两行中遇到编译错误:317& 319.我认为主要的错误与卡车类有关。

我是新手并继续查看代码,但似乎无法看到
错误。我不太了解很多花哨的东西,所以如果你能保持它对我来说简单!!!!感谢任何帮助!

以下是代码:
[...]
I''ve got a program that''s almost done, but I''m getting compile errors in
two lines: 317 & 319. I think the main error has to do with the Truck
Class.

I''m a newbie and keep looking at the code but can''t seem to see the
error. I don''t understand a lot of the fancy stuff so if you can keep it
simple for me!!!! Any help is appreciated!

Here is the code:
[...]




其中的哪些行是' '317''和''319''?什么编译错误你会得到什么?


V



And which lines in it are ''317'' and ''319''? And what compile errors do
you get?

V


Victor Bazarov写道:
Victor Bazarov wrote:
DrNoose写道:
DrNoose wrote:
我有一个程序已经差不多完成了,但我收到编译错误
两行:317& 319.我认为主要的错误与
卡车类有关。

我是新手并继续查看代码,但似乎无法看到
错误。我不太了解很多花哨的东西,所以如果你能保持它对我来说简单!!!!感谢任何帮助!

以下是代码:
[...]
I''ve got a program that''s almost done, but I''m getting compile errors
in two lines: 317 & 319. I think the main error has to do with the
Truck Class.

I''m a newbie and keep looking at the code but can''t seem to see the
error. I don''t understand a lot of the fancy stuff so if you can keep
it simple for me!!!! Any help is appreciated!

Here is the code:
[...]



其中的哪些行是''317''和''319''?你得到了什么编译错误?

V


And which lines in it are ''317'' and ''319''? And what compile errors do
you get?

V



该行是:


卡车::卡车(字符串m,int cyl,双重负载,int tow,Person

p):制造商(m),numCylinders(cyl),LoadCapacity(负载),

TowingCapacity(拖车),车主(p)


应该是这个我相信:


卡车::卡车(字符串m,int cyl,Person p,double load,int

tow):manufacturer(m),numCylinders(cyl),owner(p),LoadCapacity(load),

TowingCapacity(两个)


我把声明中的定义按错误的顺序排列了

我现在已经修复了,但它只是开了一个船载更多的错误!!!!!!!

现在为我刚修好的那条线我得到了这些错误:


(318):错误C2614: ''卡车'':非法会员初始化:

''TowingCapacity''不是基地或会员

(318):错误C2614:''卡车'':非法成员升级:

''LoadCapacity''不是基础或成员

(318):错误C2614:''卡车'':非法成员初始化:''所有者' '是

不是基地或会员

(318):错误C2614:''卡车'':非法会员初始化:

'' numCylinders''不是基础或成员

(318):错误C2614:''卡车'':非法成员初始化:

''制造商''不是基地或会员

对于这一行:


LoadCapacity = newLoad; (第339行)我收到此错误:


(339):错误C2065:''LoadCapacity'':未声明的标识符


TowingCapacity = newTowing; (第344行)我收到此错误:


(344):错误C2065:''TowingCapacity'':未声明的标识符

还有更多错误.. ..


这个似乎与这个定义有关:


// ============= =================

//卡车类定义


卡车::卡车()

{

}


Truck :: Truck(字符串m,int cyl,Person p,double load,int

tow):制造商(m),numCylinders(cyl),所有者(p),LoadCapacity(负载),

TowingCapacity(丝束)

{

}


卡车::卡车(常见卡车& theObject)

{

loadCapacity = theObject。 loadCapacity;

towingCapacity = theObject.towingCapacity;

}


double Truck :: getLoadCapacity()const

{

return loadCapacity;

}


int Truck :: getTowingCapacity()const

{

返回towingCapacity;

}


void Truck :: setLoadCapacity(double newLoad)

{

LoadCapacity = newLoad;

}


void Truck :: setTowingCapacity(int newTowing)

{

TowingCapacity = newTowing;

}


void Truck :: output()

{

cout<<"Load Capaciy:"<< LoadCapacity<< endl;

cout<<"" Tow Capacity:"<<< TowingCapacity<< endl;


}


这是同一类的声明:


// ================= ==============

//卡车类声明

// ============ ===================

类卡车:公共汽车

{

public :

卡车();

卡车(字符串m,int cyl,人员p,双重负载,int tow);

卡车(const)卡车和放大器; theObject);

double getLoadCapacity()const;

int getTowingCapacity()const;

void setLoadCapacity(double newLoad);

void setTowingCapacity(int newTowing);


void output();

//输出相应标记的数据成员。


卡车& operator =(const Truck& rtSide);

private:

double loadCapacity;

int towingCapacity;

} ;

想想我第一次编译时我只有2个错误!!!!!


The line was:

Truck::Truck(string m, int cyl, double load, int tow, Person
p):manufacturer(m), numCylinders(cyl), LoadCapacity(load),
TowingCapacity(tow), owner(p)

It should have been this I belive:

Truck::Truck(string m, int cyl, Person p, double load, int
tow):manufacturer(m), numCylinders(cyl), owner(p), LoadCapacity(load),
TowingCapacity(tow)

I had put the definitions in the wrong order from the declaration which
I have now fixed, but it just opened up a boat load more errors!!!!!!!
Now for that line that I just fixed I''m getting these errors:

(318): error C2614: ''Truck'' : illegal member initialization:
''TowingCapacity'' is not a base or member
(318): error C2614: ''Truck'' : illegal member initialization:
''LoadCapacity'' is not a base or member
(318): error C2614: ''Truck'' : illegal member initialization: ''owner'' is
not a base or member
(318): error C2614: ''Truck'' : illegal member initialization:
''numCylinders'' is not a base or member
(318): error C2614: ''Truck'' : illegal member initialization:
''manufacturer'' is not a base or member
For this line:

LoadCapacity=newLoad; (line 339) I get this error:

(339): error C2065: ''LoadCapacity'' : undeclared identifier

TowingCapacity=newTowing; (line 344) I get this error:

(344): error C2065: ''TowingCapacity'' : undeclared identifier
There are more errors....

It all seems to do with this definition:

//==============================
// Truck Class Definitions

Truck::Truck()
{
}

Truck::Truck(string m, int cyl, Person p, double load, int
tow):manufacturer(m), numCylinders(cyl), owner(p), LoadCapacity(load),
TowingCapacity(tow)
{
}

Truck::Truck(const Truck& theObject)
{
loadCapacity = theObject.loadCapacity;
towingCapacity = theObject.towingCapacity;
}

double Truck::getLoadCapacity()const
{
return loadCapacity;
}

int Truck::getTowingCapacity()const
{
return towingCapacity;
}

void Truck::setLoadCapacity(double newLoad)
{
LoadCapacity=newLoad;
}

void Truck::setTowingCapacity(int newTowing)
{
TowingCapacity=newTowing;
}

void Truck::output()
{
cout<<"Load Capaciy:"<<LoadCapacity<<endl;
cout<<"Tow Capacity:"<<TowingCapacity<<endl;

}

This is the declaration for the same class:

//===============================
// Declaration of Truck Class
//===============================
class Truck : public Vehicle
{
public:
Truck();
Truck(string m, int cyl, Person p, double load, int tow);
Truck(const Truck& theObject);
double getLoadCapacity() const;
int getTowingCapacity() const;
void setLoadCapacity(double newLoad);
void setTowingCapacity(int newTowing);

void output();
// Outputs the data members appropriately labeled.

Truck& operator=(const Truck& rtSide);
private:
double loadCapacity;
int towingCapacity;
};
To think when I first compiled this I only had 2 errors!!!!!


DrNoose写道:
DrNoose wrote:
嗨!

我有一个已经差不多完成的程序,但是我在两行中遇到了编译错误:317& 319.我认为主要的错误与卡车类有关。

我是新手并继续查看代码,但似乎无法看到
错误。我不太了解很多花哨的东西,所以如果你能保持它对我来说简单!!!!任何帮助表示赞赏!


嗯,我不知道317或319是什么行,你没想过;或者想要引用

错误信息但无论如何


[snip]

void Truck :: output()
{
cout<<"" Load Capaciy:" << LoadCapacity<< endl;
cout<<""" Tow Capacity:"<<<< TowingCapacity<< endl;

return * this;
}


这是一个错误,你无法从void函数返回任何内容。

void Person :: output()
{
cout<<"名称:"<<< newName<< endl;
返回* this;
}
Hi!

I''ve got a program that''s almost done, but I''m getting compile errors in
two lines: 317 & 319. I think the main error has to do with the Truck
Class.

I''m a newbie and keep looking at the code but can''t seem to see the
error. I don''t understand a lot of the fancy stuff so if you can keep it
simple for me!!!! Any help is appreciated!

Well I don;t what lines are 317 or 319, and you didn;t think to quote
the error messages but anyway

[snip]

void Truck::output()
{
cout<<"Load Capaciy:"<<LoadCapacity<<endl;
cout<<"Tow Capacity:"<<TowingCapacity<<endl;

return *this;
}
This is an error, you cannot return anything from a void function.

void Person::output()
{
cout<<"Name:"<<newName<<endl;
return *this;
}




同上。


总的来说,代码很好,比一般的新手代码更好。非常

有条不紊(这很好),并且很好地理解了几个重要的

概念(我假设你不是只是从一个复制(b)b。你有一些误解,你可以删除你的代码中定义的每个拷贝构造函数

和赋值运算符而不改变它的

意思是什么。你应该在你的书中查阅编译器

生成的复制构造函数和编译器生成的赋值

运算符。您会看到编译器会为您编写这些函数,并且对于许多类来说,编译器编写的函数正是您想要的那些函数。


john



Ditto.

Overall the code is good, better than average newbie code. Very
methodical (that''s good), and a good understanding of several important
concepts (I''m assuming that you didn''t just copy from a book).

You have some misconceptions, you could delete every copy constructor
and assignment operator defined in your code without changing it''s
meaning at all. You should look up in your book about the compiler
generated copy constructor and the compiler generated assignment
operator. You see the compiler will write these functions for you, and
for many classes the ones that the compiler writes are exactly the ones
that you want.

john


这篇关于课堂帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆