c++ - 未解析的外部符号, fatal error LNK1120

标签 c++ fatal-error

我正在尝试创建一个程序,将项目库存存储到动态数组中,同时跟踪项目 ID、项目描述、数量和价格。唯一的问题是我得到一个 Unresolved external symbol 错误

"struct inventory item * * list", fatal error LNK1120. 

知道问题是什么或如何解决吗?

#include <iostream>
#include <fstream>
#include <string>
#include <cctype>
#include <vector>

using namespace std;

struct inventoryitem{
    char itemid[7];
    string itemDesc;
    int quantity;
    float price;
    float retailprice;
};

inventoryitem *list[];
void add();
void edit();
void search();
void display();
void remove();
void textfile();

int main(){//main menu
    while(true){
        cout << "\nInventory Database Manager\n";
        cout << "_____________________________\n";
        cout << "What would you like to do?\n";
        cout << "1) Add item to database\n";
        cout << "2) Edit item in database\n";
        cout << "3) Search the database for an item\n";
        cout << "4) Delete an item in database\n";
        cout << "5) Display all items\n";
        //cout << "6) Exit program\n";
        cout << "Input command (1-5)\n\n";
        int input;
        cin >> input;
        switch(input){
            case 1: add();
            case 2: edit();
            case 3: search();
            case 4: remove();
            case 5: display();
            default : cout << "\nError, invalid input, try again";
        }
    }
}

int inc = 0;

void add(){
    inventoryitem item;
    cout << "\nEnter Item ID (3 letters followed by 4 digits)\n";
    cin >> list[inc]->itemid;
    for(int x = 0; x < 6; x++){//validates the item ID, checks if the first 3 digits are numbers first, then the next 4 
        if(x < 2){
            if(isalpha(item.itemid[x])){
                //do nothing
            }
            else{
                cout << "Error, itemID is 3 letters followed by 4 digits";
                break;
            }
        }
        if(x > 2){
            if(isdigit(item.itemid[x])){
                //do nothing
            }
            else{
                cout << "Error, itemID is 3 letters followed by 4 digits";
                break;
            }
        }
    }
    cout << "Enter the item's description\n";
    cin >> list[inc]->itemDesc;
    cout << "Enter the quantity of item\n";
    cin >> list[inc]->quantity;
    cout << "Enter the price of the item\n";
    cin >> list[inc]->price;
    cout << "Enter the retail price of the item\n";
    cin >> list[inc]->retailprice;


}
void edit(){}
void search(){}
void display(){}
void remove(){}
void textfile(){}

最佳答案

Clang为这一行发出更有用的编译器错误:

inventoryitem *list[];

definition of variable with array type needs an explicit size or an initializer

在 C++ 中,您最好使用众多 containers 中的一种。提供给你。例如:

std::list<inventoryitem>

关于c++ - 未解析的外部符号, fatal error LNK1120,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22601333/

相关文章:

c++ - 我如何解决包含 65k 行代码的文件导致 [bcc32 fatal error ] F1008 内存不足错误?

c++ - 从数组更改为包含数组的结构

c++ - std::declval vs crtp,无法从不完整类型推断方法返回类型

codeigniter - fatal error : Class 'CI_Model' not found in

javascript - fatal error : CALL_AND_RETRY_2 Allocation failed - process out of memory in preprocessing my js fiels

java - Android SimpleFTP 上传 FatalException

java - Android 致命信号 11 (SIGSEGV),代码 1,tid 29092 中的故障地址 0x0

C++ - Qt QObject::connect GET 跨类请求使用

c++ - 力扣210。为什么我的代码在特定情况下是错误的?

c++ - 如果比较取决于返回值,是否可以进行尾递归?