【发布时间】:2015-12-31 10:07:18
【问题描述】:
class Leg
{
public:
Leg (const char* const s , const char* const e , const double d) : startCity (s), endCity (e), distance (d) {}
friend void outputLeg( ostream& , const Leg& ) ;
private:
const char* const startCity ;
const char* const endCity ;
const double distance;
};
class Route
{
public:
/* Include two public constructors --
(1) one to create a simple route consisting of only one leg,
The first constructor's only parameter should be a const reference to a Leg object.*/
Route ( const Leg& ) : arrayHolder( new const Leg* [1] ), arraySize( 1 ), r_distance( Leg.distance ) {}
//(2) another to create a new route by adding a leg to the end of an existing route.
private:
const Leg** const arrayHolder;//save a dynamically-sized array of Leg*s as const Leg** const.
const int arraySize;//save the size of the Leg* array as a const int .
const double r_distance;//store the distance of the Route as a const double, computed as the sum of the distances of its Legs.
};
我可以澄清一下我在第一个构造函数中所做的事情。如何正确保存传递的 Leg 对象的指针?
当前得到'在构造函数'Route::Route(const Leg&)'中: 错误:“。”之前的预期主表达式令牌'
【问题讨论】: