2
votes

I'm getting a large amount of errors with the below code that I can't understand.

/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11

They all seem to be similar to the above, just with a different number at the end. This is most likely due to me trying to remove one of the class definitions from within the code.

#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()
{

}
2
string address; should be std::string address;, same for the parameter definition.πάντα ῥεῖ
Oh wow. Completely forgot about std...Dwayne H
Also one question per question please.πάντα ῥεῖ
Seems the above compiles now once there's a main() added.Dwayne H

2 Answers

1
votes

You have to use qualified name std::string

freight(std::string set_address, float set_length, float set_width, float set_height, float set_weight):

Another problem is that you defined the constructor with parameters twice: one inside the class definition and other outside the class definition. Remove one definition.

Also you defined the destructor outside the class definition. You have at first to declare it at least in the class definition.

1
votes

Use qualified std::string or propagate its namespace with using namespace std;.

Also, why are you defining then function inline in the class declaration and a second time below it?

Also, you did not declare the destructor in the class declaration.