error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

简介: <p>最近发现一个奇怪的错误,错误提示如下:</p> <p></p><pre name="code" class="cpp">error C4430: missing type specifier - int assumed. Note: C++ does not support default-int</pre><br> 出现该段错误的源码(某公司校招技术笔试题)如下:<pre

最近发现一个奇怪的错误,错误提示如下:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

出现该段错误的源码(某公司校招技术笔试题)如下:
#include<iostream>
using namespace std;

main()
{
	long x=65530;
	long countx=0;
	while(x)
	{
		countx++;
		x=x&(x-1);
	}
	cout<<countx<<endl;
	return countx;
}
编译后错误如下图提示:


解决方法如下:在Properties -> Configuration Properties -> C/C++ -> Command Line -> Additional Options中加入/wd4430 ,如下图:


不过呢?虽然问题解决了,本人也是“知其然不知其所以然”,若哪位高手看到后可以给出这样解决问题的原因,不过个人猜测与编译器内部有关,仅供参考,此猜测的原因如下段代码:

#include<iostream>
using namespace std;

main()
{
	int x=65302250;
	int countx=0;
	while(x)
	{
		countx++;
		x=x&(x-1);
	}
	cout<<countx<<endl;
	return countx;
}

编译过后没有任何问题!!!

可以看到,

int x=65302250;

没有提示错误哦~~~

我们知道int的大小是两字节,即-32768~32767,明显超出范围了。

剩下的交给武林盟主了~~~~~~~



目录
相关文章
|
6月前
|
人工智能 自然语言处理 语音技术
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
Invalid prop: type check failed for prop “index“. Expected String with value “5“问题解决
52 0
|
8月前
YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法
YOLO V5出现RuntimeError: result type Float can‘t be cast to the desired output type long int解决方法
492 0
|
10月前
|
SQL Java 数据库连接
attempted to return null from a method with a primitive return type
attempted to return null from a method with a primitive return type
91 0
|
12月前
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
Optional int parameter ‘id‘ is present but cannot be translated into a null value due to being ……
159 0
解决办法:error: unknown type name ‘__int64‘
解决办法:error: unknown type name ‘__int64‘
429 0
|
程序员 算法框架/工具 Caffe
解决办法:error: 'size_t' does not name a type、unknown type name 'size_t'
解决办法:error: 'size_t' does not name a type、unknown type name 'size_t'
584 0