错误:LNK 2019不断在我的代码中弹出,搜索中没有任何帮助。如何获取我的代码进行编译?

时间:2019-07-18 04:56:36

标签: c++ visual-studio class

所以我正在为我的C ++类做一个正在进行的项目,我们只需要将bookTypes的结构转换为一个类,并带有适当的setters / getters和一些其他特定的函数。我设法更改了所有代码,以便可以编译并通过一系列菜单,但它似乎不起作用。

//bookType class I added today
class bookType {
private:
    string bookTitle;
    string isbn;
    string author;
    string publisher;
    string dateAdded;
    int qtyOnHand;
    float wholesale;
    float retail;
    static int bookCount;
public:
    void setTitle(string);
    void setISBN(string);
    void setAuthor(string);
    void setPub(string);
    void setDateAdded(string);
    void setQtyOnHand(int);
    void setWholesale(float);
    void setRetail(float);
    static void incBookCount();
    static void decBookCount();

    string getTitle() const;
    string getISBN() const;
    string getAuthor() const;
    string getPub() const;
    string getDateAdded() const;
    int getQtyOnHand() const;
    float getWholesale() const;
    float getRetail() const;
    int getBookCount() const;

    void print();
    bool equals(bookType);
    bookType();
    bookType(string, string, string, string, string, int, float, float);
};

//one of the cpp files used
#include "serendipity.h" //this .h file has all my non-class specific prototypes
#include "bookType.h" //has my class definition

void cashier(bookType* books)
{
    string title1 = "Cashier Module";
    int len1 = title1.length();
    string date = "";
    int quantity = 0;
    char cashierChoice = '0';
    double subT = 0;
    double tax = 0;
    double total = 0;

    do {
        system("cls");

        cout << setfill(' ');
        cout << setw((SIZE_MENUS / 2) + LEN_TITLE / 2) << right << TITLE << endl;
        cout << setw((SIZE_MENUS / 2) + len1 / 2) << right << title1 << endl;
        cout << endl;

        int index = lookUpBook(books);

        if (index != -1)
        {
            system("cls");

            cout << setfill(' ');
            cout << setw((SIZE_MENUS / 2) + LEN_TITLE / 2) << right << TITLE << endl;
            cout << setw((SIZE_MENUS / 2) + len1 / 2) << right << title1 << endl;
            cout << endl;

            do
            {
                cin.clear();
                cin.ignore(256, '\n');
                cout << setw(SIZE_MENUS / 3) << "" << "Quantity of Book (There are " << books[index].getQtyOnHand() << " available): ";
                cin >> quantity;
                cout << endl;
                if (cin.fail())
                {
                    cout << setw(SIZE_MENUS / 3) << "" << "Please enter a number." << endl;
                    cout << setw(SIZE_MENUS / 3) << "";
                    system("pause");
                    cout << endl;
                }
                if (quantity > books[index].getQtyOnHand())
                {
                    cout << setw(SIZE_MENUS / 3) << "" << "Please enter a number less than " << books[index].getQtyOnHand() << "." << endl;
                    cout << setw(SIZE_MENUS / 3) << "";
                    system("pause");
                    cout << endl;
                }
            } while (quantity > books[index].getQtyOnHand() || cin.fail());

            subT = books[index].getRetail() * quantity;
            tax = subT * 0.06;
            total = subT + tax;

            books[index].setQtyOnHand(books[index].getQtyOnHand() - quantity);

            system("cls");

            cout << TITLE << endl;
            cout << endl;
            cout << "Date: " << date << endl;
            cout << endl;

            cout << setw(5) << left << "Qty";
            cout << setw(15) << left << "ISBN";
            cout << setw(40) << left << "Title";
            cout << setw(10) << left << "Price";
            cout << setw(10) << left << "Total" << endl;
            cout << endl;

            cout << setfill('-');
            cout << setw(SIZE_MENUS) << "";
            cout << endl;

            string size13 = books[index].getISBN().substr(0, 13);
            string size38 = books[index].getTitle().substr(0, 38);

            cout << setfill(' ');
            cout << setw(5) << left << quantity;
            cout << setw(15) << left << size13;
            cout << setw(40) << left << size38;
            cout.precision(2);
            cout << setw(5) << right << "$ " << setw(5) << right << fixed << books[index].getRetail();
            cout << setw(5) << right << "$ " << setw(5) << right << fixed << subT << endl;
            cout << endl;
            cout << endl;

            cout << setw(30) << right << "Subtotal";
            cout << setw(40) << "";
            cout << setw(5) << right << "$ " << setw(5) << right << fixed << subT << endl;

            cout << setw(30) << right << "Tax";
            cout << setw(40) << "";
            cout << setw(5) << right << "$ " << setw(5) << right << fixed << tax << endl;

            cout << setw(30) << right << "Total";
            cout << setw(40) << "";
            cout << setw(5) << right << "$ " << setw(5) << right << fixed << total << endl;
            cout << endl;

            cout << "Thank You for Shopping at Serendipity!" << endl;
            cout << endl;

            system("pause");
        }

        system("cls");
        cout << "Do you wish to complete another transaction? (Y/N): ";
        cin >> cashierChoice;
        cin.ignore(100, '\n');
        cout << endl;

        while (cashierChoice != 'Y' && cashierChoice != 'y' && cashierChoice != 'N' && cashierChoice != 'n')
        {
            cout << "Please enter either Y or N." << endl;
            system("pause");
            system("cls");
            cout << "Do you wish to complete another transaction? (Y/N): ";
            cin >> cashierChoice;
            cin.ignore(100, '\n');
            cout << endl;
        }

    } while (cashierChoice != 'N' && cashierChoice != 'n');



}

我得到了多个相同错误,而不是代码编译 cashier.obj:错误LNK2019:未解析的外部符号“公共:void __thiscall bookType :: setQtyOnHand(int)”(?setQtyOnHand @ bookType @@ QAEXH @ Z)在函数“ void __cdecl Cashier(class bookType *)”(?cashier中引用) @@ YAXPAVbookType @@@ Z) (这是第一个错误,我相信这是指代码行[books [index] .setQtyOnHand(books [index] .getQtyOnHand()-volume);)

0 个答案:

没有答案