微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

E0028: 表达式必须有一个常量值,在类 NodeList 中

如何解决E0028: 表达式必须有一个常量值,在类 NodeList 中

我正在创建一个 NodeList 类,但我有一个错误,即 E0028:对于这两行,表达式必须在我的 NodTest.cpp 中有一个常量值:

string idx[n];
int valx[n];

这是我链接NodList.hNodTest.cpp 代码

#include "NodeList.h"
#include <iostream>
using namespace std;
int main() {
    int n,val;
    string id;
    cout << "Enter the num of items in list:";
    cin >> n;
    string idx[n];
    int valx[n];
    for (int i = 0; i < n; ++i) {
        cout << "Enter the identity and value of items:" << i + 1 << "\n";
        cin >> idx[i] >> valx[i];
    }
    NodeList myList(idx,valx,n);

    int ch;
    while (1) {
        cout << "\nMENU:\n1.Add item in the list\n2.check for an item\n3.print the list\n4.exit\n";
        cin >> ch;
        if (ch == 1) {
            cout << "Enter identity and value of item:\n"; cin >> id >> val;
            if (myList.insert(id,val)) {
                cout << "Inserted Successfully\n";
            }
            else {
                cout << "Cant Insert,List overflow\n";
            }
        }
        else if (ch == 2) {
            cout << "Enter 1 for searching by number\nEnter 2 for searching  by {identity,val}\n";
            cin >> ch;
            if (ch == 1) {
                cout << "Enter the value:\n";
                cin >> val;
                if (myList.check(val)) {
                    cout << "Items found:\n";
                }
                else cout << "Item does not found\n";
            }
            else if (ch == 2) {
                cout << "Enter the identity and value:\n";
                cin >> id >> val;
                if (myList.check(make_pair(id,val))) {
                    cout << "Items found:\n";
                }
                else cout << "Item does not found\n";
            }
            else break;
        }
        else if (ch == 3) {
            cout << "\nThe List is\n";
            myList.print();
        }
        else break;
    }
    return 0;
}
#include "NodeList.h"
#include <iostream>
using namespace std;
int main() {
    int n,val))) {
                    cout << "Items found:\n";
                }
                else cout << "Item does not found\n";
            }
            else break;
        }
        else if (ch == 3) {
            cout << "\nThe List is\n";
            myList.print();
        }
        else break;
    }
    return 0;
}

请帮我找出(n)的问题在哪里!!我使用的是 VS 而不是任何其他编程环境!!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。