奇怪的编译器错误
Weird Compiler Errors
我无法理解下面的代码,我得到了大量的错误。
/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):
另一个问题是您用参数定义了构造函数两次:一次在类定义内部,另一次在类定义外部。删除一个定义
还在类定义之外定义了析构函数。您必须首先至少在类定义中声明它。
使用限定的std::string
或用using namespace std;
传播其命名空间
而且,您没有在类声明中声明析构函数。
相关文章:
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 如何解决gcc编译器优化导致的centos双编译器设置中的分段错误
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 重载方法的方式会在使用临时调用时生成编译器错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 有没有办法让编译器在我放置字符串而不是 nlohmann::json 对象时抛出错误?
- 致命错误 C1001 :vs2017 15.8.4 的内部错误(编译器文件"msc1.cpp",第
- C++2440错误-编译器认为字符串是常量字符
- Clang 错误 – 编译器错误或缺少一些细节?
- 视觉C++ 2017 错误?编译器优化表达式
- 配置:错误:C++编译器无法创建可执行文件
- PHP PDO_ODBC配置:错误:C 编译器无法创建可执行文件
- 致命错误 C1001:内部编译器错误(编译器文件"MSC1.cpp",第 1794 行)
- 错误:编译器限制达到简单hello world程序的堆限制
- c++链接错误:编译器找不到函数的定义
- 生成 CImg 时出现致命错误(编译器限制)
- 抛出对齐类型时出现 Clang 运行时错误.编译器错误