C ++的错误:字段'INT []'不完全类型 [英] C++ error: field has incomplete type 'int []'

查看:122
本文介绍了C ++的错误:字段'INT []'不完全类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C使虚拟机++和我碰到这个错误,

错误:字段具有不完全类型'诠释[]'
       诠释instrarr [];

我绝对不知道什么是错的int数组。有人可以来看看,让我知道我做错了,我一直在看它了一个多小时,我似乎无法找到什么微小的细节,我必须离开了。我的整个文件低于柜面你需要它,以供参考。

 的#include<&iostream的GT;
#包括LT&;&的fstream GT;
#包括LT&;串GT;
#包括LT&;&sstream GT;使用命名空间std;类虚拟机{
    私人的:        串finfo;
        串FILEDATA;
        串fconv;
        串指令;        诠释instrarr [];
        INT zerocount [];    上市:        / *辅助函数* /        INT countinstrs(字符串s){
            诠释计数= 0;            的for(int i = 0; I< s.size();我++)
                如果(S [I] =='')的计++;                返回计数;
        }        INT countlzeros(字符串s){
            诠释计数= 0;            的for(int i = 0; I< s.size();我++)
                如果(S [I] =='0'){
                    算上++;
                }其他{
                    I = s.size()+ 1;
                }
            返回计数;
        }        字符串load_program(字符串文件){
            ifstream的rdfile(文件);
                而(rdfile>>指令){
                    FILEDATA + =指令;
                    FILEDATA + =;
                }
            rdfile.close();
            返回FILEDATA;
        }        字符串convert_program(字符串fconv){
            INT instrcount = countinstrs(fconv);
            stringstream的HEXTOINT;
            无符号整型值;
            字符串s = fconv;
            字符串分隔符=;
            为size_t POS = 0;
            字符串标记;
            INT I = 0;
            而((POS = s.find(分隔符))!=字符串::非营利组织){
                令牌= s.substr(0,POS)
                INT zeroc = countlzeros(令牌);
                // zerocount [I] = zeroc;
                stringstream的HEXTOINT(标记);
                HEXTOINT>>十六进制>>值;
                // instrarr [I] =价值;
                COUT<<值<< ENDL;
                s.erase(0,位置pos + delimiter.length());
                我++;
            }
            返回;
        }        无效run_program(字符串文件){
            finfo = load_program(文件);
            fconv = convert_program(finfo);
            // execute_program();
        }
};INT主(INT ARGC,CHAR *的argv []){    VM次;
    rd.run_program(ARGV [1]);
    返回0;}


解决方案

这是pretty简单, INT [] 是一个不完整的类型,因为它缺少相关信息有多大是。在函数调用的参数,它进入与声明一个指针,而不是阵列同义,但对于defintions,如在code时,编译器当然需要知道数组多大,以便为它分配存储空间。

I'm making a virtual machine in C++ and I've run into this error,

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

I have absolutely no idea what is wrong with the int array. Can someone take a look and let me know what I've done wrong, I've been looking at it for over an hour and I can't seem to find what tiny detail I must have left out. My entire file is below incase you need it for reference.

#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;

}

解决方案

It's pretty simple, int[] is an incomplete type, as it lacks information about how large it is. In function call parameters, it goes synonymous with declaring a pointer instead of an array, but for defintions, as in your code, the compiler certainly needs to know how large the array is, in order to allocate storage for it.

这篇关于C ++的错误:字段'INT []'不完全类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆