我得到了大量的错误与下面的代码,我不能理解。
/usr/bin/ld:/usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info):重定位0具有无效的符号索引11
它们似乎都与上面的相似,只是结尾处有一个不同的数字。这很可能是因为我试图从代码中移除类定义之一。
#include <string>
using namespace std;
static const float MAX_SATCHEL_VOLUME = 0.20; // in m^3
static const float MAX_CARTON_VOLUME = 0.50; // in m^3
static const float MAX_PALLET_VOLUME = 2.00;// in m^3
static const float SATCHEL_COST_PER_KILO = 2.00; // in dollars
static const float CARTON_COST_PER_KILO = 1.00; // in dollars
static const float PALLET_COST_PER_KILO = 0.50; // in dollars
class freight
{
public:
enum FreightType
{
SATCHEL,
CARTON,
PALLET,
};
float cost()
{
return perKiloCost * weight;
}
private:
freight (string set_address, float set_length, float set_width, float set_height, float set_weight);
string address;
float length;
float width;
float height;
float weight;
FreightType type;
float perKiloCost;
~freight();
};
freight::freight (string set_address, float set_length, float set_width, float set_height, float set_weight)
{
address = set_address;
length = set_length;
width = set_width;
height = set_height;
weight = set_weight;
type = PALLET;
perKiloCost = 1.00;
{
float volume = length * width * height;
if(volume > MAX_PALLET_VOLUME)
{
type = PALLET;
perKiloCost = PALLET_COST_PER_KILO;
}
else if(volume > MAX_CARTON_VOLUME)
{
type = CARTON;
perKiloCost = CARTON_COST_PER_KILO;
}
else
{
type = SATCHEL;
perKiloCost = SATCHEL_COST_PER_KILO;
}
}
}
freight::~freight()
{
}
您必须使用限定名std::string
freight(std::string set_address, float set_length, float set_width, float set_height, float set_weight):
另一个问题是您用参数定义了两次构造函数:一次在类定义内部,另一次在类定义外部。删除一个定义。
此外,您还在类定义之外定义了析构函数。首先,您必须至少在类定义中声明它。
使用限定的std::string
或使用名称空间std;使用传播其名称空间。
还有,为什么要在类声明中内联定义then函数,然后在它下面定义第二次?
而且,您没有在类声明中声明析构函数。