hello, i am new to this site but i have used it as reference before. this is a program for one of my classes and i have everything done down to one error...

error LNK2001: unresolved external symbol "private: static char const * * Inventory::Error" (?Error@Inventory@@0PAPBDA)
1>C:\Users\Joey\documents\visual studio 2010\Projects\JHabura PA 1\Debug\JHabura PA 1.exe : fatal error LNK1120: 1 unresolved externals

#define INVENTORY_H
#include <iostream>
#include <iomanip>
#include <string>
#include <istream>
#include <fstream>
#include <vector>
#include <ctime>
using namespace std;

class Inventory
{
private:
    static int NumCustomers;
    static const char *Error[];
    static const double Taxes;

    long Inv;
    string Description;
    double price;
    char tax;

public:
    enum error_msg{NOT_FOUND, IS_DUPLICATE, E_QUANTITY};

    const long& getInventory() const {return Inv;}
    const string& getDescription() const {return Description;}
    const double & getPrice() const {return price;}
    const char& getTax() const {return tax;}

    Inventory::Inventory() : Inv(10000), Description(""), price(0.0), tax('N'){}

    Inventory(const Inventory &Inven) {*this = Inven;}
    virtual Inventory::~Inventory() {Inv = 0; price = 0.0; tax = 'N'; Description = "";}

    void operator = (const Inventory &Inven)
    {
        Inv = Inven.getInventory();
        Description = Inven.getDescription();
        price = Inven.getPrice();
        tax = Inven.getTax();
    }

    bool operator == (const Inventory &item)
    {
        return item.getTax() == tax && item.getPrice() == price && item.getDescription() == Description && item.getInventory() == Inv;
    }

    friend bool isInventory(vector <Inventory>& Inven, const int&itemNum)
    {
        for (int i = 0; i <(int) Inven.size(); i++)
        {
            if (Inven[i].Inv == itemNum)
                return true;

        }
        return false;

    }
    friend bool isDuplicate(vector <Inventory> & Inven, const Inventory&invCheck)
    {
        for (int i = 0; i < (int) Inven.size(); i++)
        {
            if (Inven[i] == invCheck)
                return true;
        }
        return false;

    }

    bool isTaxable()
    {
        return tax == 'T';
    }

    friend istream& operator >> (istream& input, const Inventory &item)
    {
        operator >> (input, (Inventory &)item);
    }

    friend istream& operator >> (istream& input, Inventory &item)
    {
        if (!input.eof())
        {
            input >> item.Inv >> item.Description >> item.price >> item.tax;
        }
        return input;
    }

    static string getReceipt(double sum, double taxes)
    {
        char totalRec[1000];
        sprintf(totalRec, "/n%s/nSub Total: %10.21f/nTaxes: %10.21f/n%s/nTotal: %10.21f/n%s/n", sum, taxes, sum+taxes);
        string rec = totalRec;
        return rec;

    }

    friend ostream& operator << (ostream& out, Inventory &item)
    {
        out << setw(5) << item.getInventory() << " " << setw(12) << item.getDescription() << " " << setw(8) << fixed << setprecision(2) << item.getPrice() << " " << item.getTax();
        return out;
    }

    static string getItem(Inventory &item, const int& Quantity, double& Tax, double Sum)
    {
        string dataReturn;
        char Item[100];
        memset(Item, 0, sizeof(Item));
        string d = item.getDescription();
        double p = item.getPrice();
        string T = item.isTaxable() ? "T" : "N";

        sprintf(Item, "12.12s %3d @ %6.21f %-2.2s %7.21f", d, Quantity, p, T.c_str(), Quantity * p);
        Sum += Quantity * item.getPrice();

        if (item.isTaxable())
        {
            Tax += Taxes * (Quantity * item.getPrice());

        }
        dataReturn = Item;
        return dataReturn;


    }

    static string getError(int index, long Inv)
    {
        string dataReturn;
        char error[100];
        if (index >= NOT_FOUND || index <= E_QUANTITY)
        {
            sprintf(error, Error[index], Inv);
            dataReturn = error;
        }
        return dataReturn;
    }

    static string search4Item(vector<Inventory>& inv, const long& InvenNum, const int& Quantity, double& Tax, double Sum)
    {
        string dataReturn;
        bool Found = false, Duplicate = false, Quantity1 = Quantity >0;
        int Found1 = 0;

        if (!Quantity1)
        {
            dataReturn = getError(E_QUANTITY, InvenNum);

        }
        for (int i = 0; i < (int) inv.size(); i++)
        {
            if (inv[i].getInventory() == InvenNum)
            {
                if (Found)
                {
                    if (dataReturn.length() > 0)
                    {
                        dataReturn += "/n";
                    }
                    dataReturn += getError(IS_DUPLICATE, InvenNum);
                    Duplicate = true;

                }
                else
                {
                    Found = true;
                    Found1 = i;
                }
            }
        }
        if (!Duplicate && Quantity && Found)
        {
            dataReturn = getError(NOT_FOUND, InvenNum);

        }
        return dataReturn;
    }


};

and here is my .cpp file

#include "Inventory.h"
#include <iostream>
#include <istream>
#include <fstream>
using namespace std;


void main()
{
    filebuf Invent1;
    Invent1.open("inventory.txt", ios::in);

    filebuf Receipt;
    Receipt.open("receipt.txt", ios::out);

    istream inv(&Invent1);
    ostream rec(&Receipt);

    vector <Inventory> v;
    Inventory item;

    while (!inv.eof())
    {
        inv >> item;
        if (item.getDescription() != "")
        {
            v.push_back(item);
        }

    }

    for (int i = 0; i < (int) v.size(); i++)
    {
        cout << v[i] << endl;


    }

    char input;
    long invenNum = 0;
    int quantity = 0;
    double tax = 0;
    double sum = 0;
    string out = "";

    do
    {
        input = 0;
        invenNum = 0;
        quantity = 0;

        cout << "Enter the inventory number and the quantity of each seperated by a space: " << endl;
        cin >> invenNum >> quantity;
        if (quantity != 0)
        {
            input = 'y';
            out = item.search4Item(v, invenNum, quantity, tax, sum);
            cout << out << endl;
            rec << out << endl;


        }
        else 
        {
            rec << Inventory::getReceipt(sum, tax);
            cout << Inventory::getReceipt(sum, tax);
            cout << endl << "would you like to help another customer? y or n" << endl;
            cin>>input;
            if (tolower(input == 'y'))
            {
                sum = 0;
                tax = 0;

            }

        }


    } while (tolower(input) == 'y');
    system("pause");










}

hopefully you guys will be able to see what it is that i am missing here... i have been staring at this for an hour and a half now

Recommended Answers

All 5 Replies

static const char *Error[];

This is only a declaration, you still need to define Error:

class Inventory
{
    static const char *Error[];

    ...
};

const char *Inventory::Error[100];

100 in this case is an arbitrary number, but since it's an array you need to pick something.

const char *Inventory::Error[100];

alright now where would i put this? i get this when i put it in the .h file:
1>c:\users\joey\documents\visual studio 2010\projects\jhabura pa 1\jhabura pa 1\inventory.h(32): error C2086: 'const char *Inventory::Error[]' :
which from what i read is that its defined twice?

you should be initializing it your constructor

alright now where would i put this?

Anywhere except the header. It's a definition, which means it can only be defined once.

alright i figured that out, but now i am typing the information into the compiler and no matter what it is telling me its not in inventory every time except when i do the one that i purposely put double inventory on

NEVERMIND this i found the problem i got distracted when writing that part thanks for the help guys i appreciate it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.