C++错误:字段的类型不完整"int []"

C++ error: field has incomplete type 'int []'

本文关键字:int 错误 字段 类型 C++      更新时间:2023-10-16

我正在用C++制作一个虚拟机,遇到了这个错误,

error: field has incomplete type 'int []' int instrarr[];

我完全不知道int数组出了什么问题。有人能看一眼,告诉我我做错了什么吗?我已经看了一个多小时了,似乎找不到我遗漏了什么小细节。我的整个文件在下面,以备您参考。

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
class vm {
    private:
        string finfo;
        string filedata;
        string fconv;
        string instruction;
        int instrarr[];
        int zerocount[];
    public:
        /* Helper functions */
        int countinstrs(string s) {
            int count = 0;
            for (int i = 0; i < s.size(); i++)
                if (s[i] == ',') count++;
                return count;
        }
        int countlzeros(string s) {
            int count = 0;
            for (int i = 0; i < s.size(); i++)
                if (s[i] == '0') {
                    count++;
                } else {
                    i = s.size() + 1;
                }
            return count;
        }
        string load_program(string file) {
            ifstream rdfile(file);
                while(rdfile >> instruction) {
                    filedata += instruction;
                    filedata += ",";
                }
            rdfile.close();
            return filedata;
        }
        string convert_program(string fconv) {
            int instrcount = countinstrs(fconv);
            stringstream hextoint;
            unsigned int value;
            string s = fconv;
            string delimiter = ",";
            size_t pos = 0;
            string token;
            int i = 0;
            while ((pos = s.find(delimiter)) != string::npos) {
                token = s.substr(0, pos);
                int zeroc = countlzeros(token);
                //zerocount[i] = zeroc;
                stringstream hextoint(token);
                hextoint >> hex >> value;
                //instrarr[i] = value;
                cout << value << endl;
                s.erase(0, pos + delimiter.length());
                i++;
            }
            return "";
        }
        void run_program(string file) {
            finfo = load_program(file);
            fconv = convert_program(finfo);
            //execute_program();
        }
};
int main(int argc, char* argv[]) {
    vm rd;
    rd.run_program(argv[1]);
    return 0;
}

很简单,int[]是一个不完整的类型,因为它缺乏关于它有多大的信息。在函数调用参数中,它与声明指针而不是数组同义,但对于定义,如在代码中,编译器当然需要知道数组有多大,以便为它分配存储。