同一个错误,产生的原因可能会有很多很多,因为编译器是程序写死的东西,很多时候它也不知道究竟哪里出的错误。
本程序报错如下:
错误 15 error C2143: 语法错误 : 缺少“;”(在“*”的前面) e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
错误 16 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
警告 17 warning C4183: “GetDocument”: 缺少返回类型;假定为返回“int”的成员函数 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
错误 18 error C2440: “初始化”: 无法从“int *”转换为“CMyPointCloudDoc *” e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 84
错误 19 error C2556: “CMyPointCloudDoc *CMyPointCloudView::GetDocument(void) const”: 重载函数与“int *CMyPointCloudView::GetDocument(void) const”只是在返回类型上不同 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 126
错误 20 error C2371: “CMyPointCloudView::GetDocument”: 重定义;不同的基类型 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 126
错误 21 error C2227: “->drawOBB”的左边必须指向类/结构/联合/泛型类型 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 251
错误 22 error C2227: “->drawVertexNormal”的左边必须指向类/结构/联合/泛型类型 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 256
错误 23 error C2227: “->readFile”的左边必须指向类/结构/联合/泛型类型 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 520
错误 24 error C2227: “->NeighborVectorMean”的左边必须指向类/结构/联合/泛型类型 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 591
错误 25 error C2227: “->NeighborVectorMean”的左边必须指向类/结构/联合/泛型类型 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 668
警告 26 warning C4018: “<”: 有符号/无符号不匹配 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 679
警告 27 warning C4018: “<”: 有符号/无符号不匹配 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 681
警告 28 warning C4018: “<”: 有符号/无符号不匹配 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 725
警告 29 warning C4018: “<”: 有符号/无符号不匹配 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 750
警告 30 warning C4018: “<”: 有符号/无符号不匹配 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 783
错误 31 error C2227: “->drawOBB”的左边必须指向类/结构/联合/泛型类型 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.cpp 945
错误 32 error C2143: 语法错误 : 缺少“;”(在“*”的前面) e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
错误 33 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
警告 34 warning C4183: “GetDocument”: 缺少返回类型;假定为返回“int”的成员函数 e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
错误 35 error C2143: 语法错误 : 缺少“;”(在“*”的前面) e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
错误 36 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int e:\pointcloud\mypoint\mypointcloud\mypointcloud\mypointcloudview.h 20
网上查到的解决方式大致有以下几种:
1、#include 头文件顺序问题,
错误: #include "MyPointCloudView.h"
#include "MyPointCloudDoc.h"
正确: #include "MyPointCloudDoc.h"
#include "MyPointCloudView.h"
2、#include view头文件时前面必须#include doc头文件
3、变量的声明没有全部放到最前面,被一部分其他语句隔开了
最终发现我的并非这三类问题,认真考虑后将某个cpp中 的#include "MyPointCloudView.h"删除,发现错误解决。
将此错误总结下来,一、提醒自己不能引入不必要的头文件以免产生错误;
二、可以给初次接触到此类错误的童鞋提供帮助。