gpt4 book ai didi

c++ - 奇怪的编译器错误

转载 作者:搜寻专家 更新时间:2023-10-31 02:19:56 25 4
gpt4 key购买 nike

我无法理解以下代码中的大量错误。

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 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):

另一个问题是您两次定义带参数的构造函数:一次在类定义内,另一次在类定义外。删除一个定义。

您还在类定义之外定义了析构函数。您首先必须至少在类定义中声明它。

关于c++ - 奇怪的编译器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33317093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com