extra qualification ‘ContourLine::’ on member ‘GetLengthBetweenPoint’ [-fpermissive] 的解决方法

文章源代码如下:

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的长度,并把长度结果存入length
void 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,编译通过,错误解决。







				
时间: 2024-09-08 10:33:55

extra qualification ‘ContourLine::’ on member ‘GetLengthBetweenPoint’ [-fpermissive] 的解决方法的相关文章

C++编程中错误及警告信息(2) extra qualification

Explanation 实例: - class Hello { - void Hello::hello(); - }; - 提示(g++): Hello.h:17: error: extra qualification 'Hello::' on member 'hello' 这通常是拷贝代码引起的,应改为: - class Hello { - void hello(); - }; - Reference http://hi.baidu.com/zjugator/blog/item/77bb6ce

藏身时间类中的妖孽

下面的代码,是一位同学为<初识对象>中的项目3时间类写的.但错误有点诡异,他在QQ群中求助. #include <iostream> using namespace std; class Time { public: void set_time(); void show_time(); void add_sec(int); void add_minute(int); void add_hour(int); void add_a_sec() { sec=sec+1; if(sec==

c++-C++成员函数前加类型,在g++下的编译错误,在vs2012下编译通过,什么原因

问题描述 C++成员函数前加类型,在g++下的编译错误,在vs2012下编译通过,什么原因 abc.cpp#include using namespace std;class MY{public: void MY::print() { cout<<""sdjflsdj""<<endl; } };int _tmain(int argc _TCHAR* argv[]){ MY my; my.print();return 0; } g++ abc.

Qt中is not a member of ‘std’错误的解决

Qt教程(C++ GUI Qt 4)中,第15章例程,tripserver编译出错,提示是:"is not a member of 'std'""错误. 错误原因是:C++标准库实现有问题,解决方法如下: 在主源代码中加入:#include <stddef.h> 然后出错的地方,去掉 "std::" 编译通过.

代码从windows下visual studio到andriod平台迁移实现步骤

代码从windows下visual studio到andriod平台迁移实现步骤: 前言 前言也是迁言,从windows的visual studio 2012平台迁移到Android平台上,需用修改挺多的代码和需用注意地方. 我们当然的平台当初就考虑了其他平台跨平台的应用问题,所以一开始在windows下就是用cmake来完成工程的建立的,cMakeLists.txt文件都做了一些处理,但是此时只是更针对或说首先保证windows下的编译和使用. 谨此做个记录. 1. modify cMakeL

lnamp环境搭建

LNAMP+CentOS 6.0(64位)编译安装 CentOS 6.0 Apache2.PHP.MySQL.Nginx 参考: http://aiwei.us/5422.html LNAMP+CentOS 6.0(64位) 编译安装 一.系统约定 软件源代码包存放位置 /usr/local/src 二.系统环境初始化 01. 检查系统是否正常 # more /var/log/messages(检查有无系统级错误信息) # dmesg (检查硬件设备是否有错误信息) # cat /proc/cp

全新64位CentOS6.X上LAMP架构搭建备忘

======================================================================================== PS: 生产环境必须都安装GA版本--很多配置还很不成熟--还需要不断完善和改进-- 安装mysql-5.1.36 tar xf mysql-5.1.36.tar.gz -C /usr/src/ ./configure --prefix=/usr/local/mysql --enable-local-infile --w

Discuz论坛的SEO优化方案

中介交易 http://www.aliyun.com/zixun/aggregation/6858.html">SEO诊断 淘宝客 云主机 技术大厅 设discuz已启用伪静态功能,使用5.0/5.5 GBK 版本: 1.meta,content 优化 2.内容页的网页复制问题 3.robots.txt使用及其它 更新 discuz5.5的robots.txt问题 DZ 禁止一个版面帖子的收录的补充 一.meta的优化 discuz的后台可以对meta信息进行设置,甚至可以添加自己的头部信

CentOS6.3系统中Gitosis安装部署步骤

  Git作为一个分布式的版本控制系统,使用git的时候,一般和服务器通讯使用的是ssh协议,用ssh的主要优点是速度快(传输前数据会先压缩,比HTTP快),安全,方便读写.    客户端通过ssh访问服务器端的验证方式一般有两种,一种是用户名密码的方式,一种是使用公私钥认证的方式. 使用公私钥的方式比较方便,无需每次登录输入密码.    某个受信任的客户端的公钥会被设置在服务器端的 ~/.ssh/authorized_keys文件中,有关此文件的格式可以参见 sshd的用户手册 man ssh