由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
I cannot write c++ arrays now because of "error C4430: missing type specifier - int assumed. Note: C++ does not support default-int"
所有想把我从痛苦中拯救出来的英俊的人问好,
我是 c++ 的新手,在完成了 w3schools 告诉您的字符串、循环、数组、指针等通常的介绍性内容后,我决定编写一些代码。我决定从一个简单的挑战开始,要求你编写一些循环,从最高到最低或相反地对一些整数进行排序,而不使用排序函数(有人告诉我有这样的东西(。
并且代码仍然不起作用。但这对我来说很正常,只要我能理解为什么它不起作用。(请不要回答为什么不起作用,请继续阅读(
#include <iostream>
using namespace std;
int age[4] = { 26, 14, 6, 43};
int num = 4;
int a = 0;
double previous = 0;
int chosen = age[a];
void first() {
while (result[0] || result[num] == 0){
for (int i = 0; a != num; i++) {
chosen = age[a];
previous = age[i];
if (chosen < (previous + 0.01) ) {
chosen = result[a];
a++;
previous = age[0];
i = 0;
}
}
}
}
void last()
{
for (int i = 0; i < num; i++) {
cout << result[i] << "n";
}
}
int main() {
first();
last();
}
所以我试图看看我的主要"if 语句"是否正常工作,并在引入变量的地方添加了已经分配的 result[0] 值。
int a = 0;
double previous = 0;
result[0] = 20;
int chosen = age[a];
然后当我运行程序时,发生了此错误:
error C2466: cannot allocate an array of constant size 0
(18,14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
(18,16): error C2440: 'initializing': cannot convert from 'int' to 'int [0]'
(18,12): message : There are no conversions to array types, although there are conversions to references or pointers to arrays
(第 18 行是我分配结果[0]的地方(
当我看到这个时,我就像"我想我很愚蠢,我不知道如何分配数组",但后来我检查了是否是这种情况,我认为事实并非如此。
然后我理解了第一个错误,因为我尝试将结果 [0] 更改为结果 [4],它消失了,但我不知道第二个错误在说什么。
所以,正如一位智者可能说的那样,"如果你有谷歌无法回答的编码问题,那就去堆栈溢出吧"。
所以我做到了。但我找到的文章是代码,与我的中文知识相当。如果你还在想,我一个中文单词都不认识。而且我没有找到更好的文章来解释如何在初学者的纯编码中解决问题。我刚刚开始在大流行中编写 c++,除了英语之外,我还什么都不懂。
如果有人能告诉我这个错误是什么意思,以及他下面的其他错误朋友怎么可能消失,我将不胜感激。
你还没有声明result
. C 认为使用未声明的变量会导致编译器假定该变量被声明为extern int
。 一些C++编译器支持此功能以实现向后兼容性,但它不是标准C++的一部分。
在这种情况下,编译器似乎支持这一点,因此它假定extern int result;
因为它没有看到此名称的声明。
这会导致两种诊断:
- 编译器警告您有关"默认
int
"声明,并且已弃用:">缺少类型说明符 - 假定为 int"> - 然后编译器告诉你,你不能下标一个
int
(如果result
是一个int
,result[0]
没有意义(:"不能从'int'转换为'int [0]'">
为result
添加数组声明以解决此问题。
- 在提升multi_index容器中,是否定义了"default index"?
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 缺少类型说明符 - 假定为 int.注意 c++ 不支持 default-int
- 错误:C4430:缺少类型说明符-假定为int.注意:C++不支持default-int
- c++default-int中的语法错误
- C++ does not support default-int
- VisualStudio 2010 Express-C++上的RDTSC不支持default-int
- VC++缺少类型说明符-假定为int.注意:C++不支持default-int
- C2143 缺少 '*' 之前的';' 和 C 4430 缺少类型说明符 - 假定为 int。注意 C++ 不支持 default-int
- 错误c4430缺少类型说明符-假定为int.注意:c++不支持default-int生成器
- c++ int switch语句总是指向' default '