C++错误:字段的类型不完整"int []"
C++ error: field has incomplete type 'int []'
我正在用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[]
是一个不完整的类型,因为它缺乏关于它有多大的信息。在函数调用参数中,它与声明指针而不是数组同义,但对于定义,如在代码中,编译器当然需要知道数组有多大,以便为它分配存储。
相关文章:
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- C++错误:"error: int aaa::bbb is protected within this context"
- 错误:从"int"到枚举c++的转换无效
- 当我在第一个循环中使用"auto"时,它工作正常,但是使用"int"它会给出错误,为什么?
- 我的 int main() 中出现堆栈溢出错误
- std::cout输出int时出现编译错误
- 在函数中使用 const int size 参数创建数组会在 Visual Studio 中抛出错误 C++:表达式的计
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- 运行时错误:引用绑定到类型为"int"的空指针
- 为什么我会收到"invalid conversion from 'Queue*/Stack*' to 'int'"错误消息?
- 类型"const char[2]"的值不能隐式转换为"int"错误C++
- 如何在<int>错误 C2338 中组织 map<set<multiset>,int> C++
- C++ sendto() 给出"invalid conversion from ‘int (*)(int, int, int)throw ()’ to ‘int’"错误
- 缺少类型说明符-假定为int错误
- 使用int错误进行浮点变量计算
- 数组到数组 -- 将'int*'分配给 'int 错误C++中的不兼容类型
- 为什么我会收到"cannot convert from Dequeu<int> to int"错误?
- int* 转换不允许 int 错误的原因是什么?
- c++将void*强制转换为int错误
- 奇怪的QT无符号Int错误