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

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

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,明显超出范围了。

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

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-02 23:40:45

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int的相关文章

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

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 错误类型: 缺失类型表述 错误原因: 函数前未写函数的返回类型,由此导致了这个错误 解决方法: 以后写函数,不管是声明还是定义,都要加上返回类型,尤其是返回类型是VOID时,更要加上 不要省略 error C4430: missing type specifier - int assumed. Note: C++ do

..\SYSTEM\usart\usart.c(48): error: #260-D: explicit type is missing (&quot;int&quot; assumed)

..\SYSTEM\usart\usart.c(48): error:  #260-D: explicit type is missing ("int" assumed) SYSTEM\usart\usart.c(48) 第48行报错,如图 添加 void  不报错,编译通过 原文地址:https://www.cnblogs.com/ys77/p/11539907.html

error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

1 #include<iostream> 2 using namespace std; 3 4 5 extern int i; 6 extern float f(float a); 7 float b; 8 float f(float a){ 9 return a+1.0; 10 } 11 int i; 12 int h(int x) 13 { 14 return x*i; 15 } 16 17 main() 18 { 19 b=1.0; 20 i=2; 21 f(b); 22 h(i); 2

error C4430: 缺少类型说明符 - 假定为 int

原文地址:error C4430: 缺少类型说明符 - 假定为 int.注意: C++ 不支持默认 int作者:tony c:evanworkspace11netwowkippack.h(50) : error C2146: 语法错误 : 缺少“;”(在标识符“nSourPort”的前面) c:evanworkspace11netwowkippack.h(50) : error C4430: 缺少类型说明符 - 假定为 int.注意: C++ 不支持默认 int c:evanworkspace1

Assets/FollowDestination.cs(6,13): error CS0246: The type or namespace name `NavMeshAgent&#39; could not be found. Are you missing `UnityEngine.AI&#39; using directive?的解决方案

问题的出现与描述 在Unity中创建一个NPC,使它一直跟踪一个目标Destination,C#脚本代码如下,错误信息描述如下 using System.Collections; using System.Collections.Generic; using UnityEngine; public class FollowDestination : MonoBehaviour { private NavMeshAgent ThisAgent = null; public Transform De

【C++注意事项】5 Top-level const , The auto and decltype Type Specifier

top-level const As we've seen, a pointer is an object that can point to a different object. As a result, we can talk independently about whether a pointer is const and whether the objects to which it can point are const. we use the top-level const to

error items-9022:missing required icon file.the bundle does not contain an app icon for iPhone/iPad Touch of exactly &#39;120x120&#39; pixels,in.pen format for ios versions &gt;= 7.0

error items-9022:missing required icon file.the bundle does not contain an app icon for iPhone/iPad Touch of exactly '120x120' pixels,in.pen format for ios versions >= 7.0 最近提交itunesconnect应用时,有个警告说缺少120x120图标 以下是本人解决方法: 添加Icon_120x120.png-->.plist添

error C2143 &amp; error C4430

错误 1 error C2143: 语法错误 : 缺少";"(在"*"的前面) 错误 2 error C4430: 缺少类型说明符 - 假定为 int.注意: C++ 不支持默认 int 错误 3 error C4430: 缺少类型说明符 - 假定为 int.注意: C++ 不支持默认 int 解决办法: 1.检测出错文件中需要include的文件都已include 2.检测已include文件是否出错(一般是这样的) 2.1 头文件宏出错 2.2类少 ; 标点 2

The constructor ClassPathXmlApplicationContext(String) refers to the missing type BeansException

"The constructor ClassPathXmlApplicationContext(String) refers to the missing type BeansException" "构造函数ClassPathXmlApplicationContext(字符串)是指缺失类型BeansException" 出现错误的原因:jar没有正确引入,即使表面上你能import包. import org.junit.Test; import org.spring