extra qualification ‘ContourLine::’ on member ‘GetLengthBetweenPoint’ [-fpermissive] 的解决方法
来源:互联网 发布:java word在线编辑 编辑:程序博客网 时间:2024/05/29 18:06
文章源代码如下:
Shapefile.h
class ContourLine{public:ContourLine();//ShapeFile(char *);~ContourLine(void);void ReadContour(char*);void SavaContour(char*);vector<Line> mContours;//等高线double MinElevation;double MaxElevation; int lineNumber;//shpfile数据中线多个数int pointNumber;//shpfile数据中点多个数private:char *FilePath; //数据路径public:void SetPath(char *path);double ContourLine::GetLengthBetweenPoint(Point P1,Point P2);void ContourLine::GetLength(Line& pContour);public:double minx,miny,maxx,maxy;};
Shapefile.cpp
//构造函数ContourLine::ContourLine(){OGRRegisterAll();pointNumber = 0;}ContourLine::~ContourLine(void){}void ContourLine::ReadContour(char *heightName){ mContours.clear();OGRDataSource* poDS = OGRSFDriverRegistrar::Open( this->FilePath, FALSE );if( poDS == NULL ){return;}OGRLayer* poLayer = poDS->GetLayer(0);if (poLayer == NULL){return;}poLayer->ResetReading();OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();OGRFeature* poFeature = poLayer->GetNextFeature(); int number=0;Line tempContour;while( poFeature != NULL ){OGRGeometry* poGeometry = poFeature->GetGeometryRef();OGRLineString *poPolyline = (OGRLineString *) poGeometry;tempContour.Elevation= poFeature->GetFieldAsDouble (heightName);if (tempContour.Elevation < 0 || poPolyline->getNumPoints() < 3){poFeature = poLayer->GetNextFeature();continue;}int ptNumber = poPolyline->getNumPoints();pointNumber +=ptNumber;for(int i = 0; i < ptNumber; i++){Point Point;Point.x=poPolyline->getX(i);Point.y=poPolyline->getY(i);tempContour.Points.push_back(Point);}//计算tempContour的长度this->GetLength(tempContour);if(number==0){this->MaxElevation=this->MinElevation=tempContour.Elevation;}else{if(tempContour.Elevation<this->MinElevation) this->MinElevation=tempContour.Elevation; if(tempContour.Elevation>this->MaxElevation) this->MaxElevation=tempContour.Elevation;}number++;mContours.push_back(tempContour);tempContour.Points.clear(); poFeature = poLayer->GetNextFeature();}this->lineNumber=number;}void ContourLine::SavaContour(char *FilePath){char FileName[MaxFileNameSize]; char *p=strrchr(FilePath,'\\')+1;strcpy(FileName,p);int i=0,j=0;while(i<MaxFileNameSize &&FileName[i]!='\0' &&FileName[i]!='.') i++; if(i !=MaxFileNameSize) FileName[i]='\0'; const char *pszDriverName = "ESRI Shapefile"; OGRSFDriver *poDriver; poDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(pszDriverName ); if( poDriver == NULL ) { printf( "%s driver not available.\n", pszDriverName ); return; } OGRDataSource *poDS; poDS = poDriver->CreateDataSource( FilePath, NULL ); if( poDS == NULL ) { printf( "Creation of output file failed.\n" ); return; } OGRLayer *poLayer; poLayer = poDS->CreateLayer(FileName, NULL, wkbLineString, NULL ); if( poLayer == NULL ) { printf( "Layer creation failed.\n" ); return; } OGRFieldDefn oField( "contour", OFTReal ); if( poLayer->CreateField( &oField ) != OGRERR_NONE ) { printf( "Creating field failed.\n" ); return; }int LineNumber=static_cast<int>(mContours.size());for(i=0;i<LineNumber;i++){OGRFeature *poFeature=new OGRFeature( poLayer->GetLayerDefn() );poFeature->SetField( "contour", mContours[i].Elevation ); OGRLineString *poPolyline = new OGRLineString();int num=static_cast<int>(mContours[i].Points.size()); poPolyline->setNumPoints(num); for(j=0;j<num;j++){poPolyline->setPoint(j,mContours[i].Points[j].x,mContours[i].Points[j].y);}poFeature->SetGeometryDirectly(poPolyline); if( poLayer->CreateFeature( poFeature ) != OGRERR_NONE ) { printf( "Failed to create feature in shapefile.\n" ); return; }} OGRDataSource::DestroyDataSource( poDS );}void ContourLine::SetPath(char *path){FilePath = path;}//计算2点之间的距离double ContourLine::GetLengthBetweenPoint(Point P1,Point P2){double length;length = sqrt((double)((P2.x - P1.x)*(P2.x - P1.x) + (P2.y - P1.y)*(P2.y - P1.y)));return length;}//计算线pContour的长度,并把长度结果存入lengthvoid ContourLine::GetLength(Line& pContour){double tempLength;//两点之间的距离double totalLength;//一条线的距离totalLength = 0;//pContour中点的数目int lineNumber = pContour.Points.size();for(int i = 0; i < lineNumber-1;i++){tempLength = GetLengthBetweenPoint(pContour.Points[i],pContour.Points[i+1]);totalLength = totalLength + tempLength;}//返回线段长度pContour.Length = totalLength;}
在用G++编译的时候输入命令:g++ -c Shapefile.cpp -o Shapefile
会提示如下错误:
Shapefile.h:40:9: error: extra qualification ‘ContourLine::’ on member ‘GetLengthBetweenPoint’ [-fpermissive]
Shapefile.h:41:7: error: extra qualification ‘ContourLine::’ on member ‘GetLength’ [-fpermissive]
错误的原因是:类的定义中
double ContourLine::GetLengthBetweenPoint(Point P1,Point P2);void ContourLine::GetLength(Line& pContour);
不需要用
double ContourLine::,或者类的函数声明和类的定义是放在一个文件里面,也不许要用***::
上述错误代码改为
double GetLengthBetweenPoint(Point P1,Point P2);void GetLength(Line& pContour);
OK,编译通过,错误解决。
- extra qualification ‘ContourLine::’ on member ‘GetLengthBetweenPoint’ [-fpermissive] 的解决方法
- extra qualification 'HelloWorld::' on member 'HelloWorld' [-fpermissive]
- error: extra qualification ‘resip::LinkuMsgSocket::’ on member ‘parserRecved’ [-fpermissive]
- 报错: extra qualification 'HelloWorld::' on member 'getJsonFromFile' [-fpermissive]
- extra qualification ‘Matrix::’ on member ‘rowTimesCol’
- 错误:extra qualification “Pieview ::”on member ‘edit’
- c++编译 extra qualification '类名' on member '变量名' error
- cygwin构建C++中关于extra qualification 额外的限定 解决方法
- c++ extra qualification
- Cocos移植apk时出现的extra qualification错误
- C++: Compile error: extra qualification
- C++: Compile error: extra qualification
- gcc中extra qualification错误
- gcc中extra qualification错误
- gcc g++ 3.4和4.5的区别 extra qualification ‘const char*’ to ‘char*’等错误
- ADT 下编译cocos2dx项目自己创建的项目报extra qualification错误
- g++编译错误error: extra qualification
- 【c++】cannot declare member function *** to have static linkage [-fpermissive]
- silverlight 跨域访问、在IIS 部署、动态绑定图片(转)
- 关于@property及@synthesize以两Demo简单说明
- ios URLConnection Cache
- netbeans下如何使用库
- 关乎于信仰
- extra qualification ‘ContourLine::’ on member ‘GetLengthBetweenPoint’ [-fpermissive] 的解决方法
- cocos2d-x总结(六) cocos2d-x与ISO内存管理
- mysql limit 优化 百万至千万级快速分页 –复合索引的引用并应用于轻量级框架
- Js获取当前日期时间及其它操作
- PIL
- 关于c语言中变量赋值问题
- 10个iPhone开发网站、论坛、博客
- 自动fdisk脚本
- Android开发中完全退出程序的三种方法