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,编译通过,错误解决。