c++程序出错了,哪位大神帮帮我
#include<iostream>#include<math.h>usingnamespacestd;classpoint{private:intx;inty;publ...
#include<iostream>
#include<math.h>
using namespace std;
class point
{
private:
int x;
int y;
public:
point(int a,int b)
{
x=a;
y=b;
}
friend double distance (point p1,point p2);
};
double distance(point p1,point p2)
{
double d;
d=pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2);
return sqrt(d);
}
int main()
{
point p1(3,4),p2(0,0);
cout<<"两点之间的距离为:"<<distance(p1,p2)<<endl;
return 0;
}
错误
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h||In instantiation of 'struct std::iterator_traits<point>':|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_funcs.h|114| required by substitution of 'template<class _InputIterator> typename std::iterator_traits::difference_type std::distance(_InputIterator, _InputIterator) [with _InputIterator = point]'|
F:\c语言练习\zuoye\main.cpp|26|required from here|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|166|error: no type named 'iterator_category' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|167|error: no type named 'value_type' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|168|error: no type named 'difference_type' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|169|error: no type named 'pointer' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|170|error: no type named 'reference' in 'class point'|
||=== 生成完成: 6 错误, 2 警告 (0 分, 2 秒) ===| 展开
#include<math.h>
using namespace std;
class point
{
private:
int x;
int y;
public:
point(int a,int b)
{
x=a;
y=b;
}
friend double distance (point p1,point p2);
};
double distance(point p1,point p2)
{
double d;
d=pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2);
return sqrt(d);
}
int main()
{
point p1(3,4),p2(0,0);
cout<<"两点之间的距离为:"<<distance(p1,p2)<<endl;
return 0;
}
错误
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h||In instantiation of 'struct std::iterator_traits<point>':|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_funcs.h|114| required by substitution of 'template<class _InputIterator> typename std::iterator_traits::difference_type std::distance(_InputIterator, _InputIterator) [with _InputIterator = point]'|
F:\c语言练习\zuoye\main.cpp|26|required from here|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|166|error: no type named 'iterator_category' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|167|error: no type named 'value_type' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|168|error: no type named 'difference_type' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|169|error: no type named 'pointer' in 'class point'|
f:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\include\c++\bits\stl_iterator_base_types.h|170|error: no type named 'reference' in 'class point'|
||=== 生成完成: 6 错误, 2 警告 (0 分, 2 秒) ===| 展开
展开全部
注意看出错信息
In instantiation of 'struct std::iterator_traits<point>':|
说明在提到的头文件stl_iterator_base_types.h当中还有一个也叫point的类
把你的类改个名字吧
比如改成Point
那么就是
#include<iostream>
#include<math.h>
using namespace std;
class Point
{
private:
int x;
int y;
public:
Point(int a,int b)
{
x=a;
y=b;
}
friend double distance (Pointp1,Pointp2);
};
double distance(Pointp1,Point p2)
{
double d;
d=pow(p1.x-p2.x,2)+pow(p1.y-p2.y,2);
return sqrt(d);
}
int main()
{
Point p1(3,4),p2(0,0);
cout<<"两点之间的距离为:"<<distance(p1,p2)<<endl;
return 0;
}
试试吧 其他的没什么问题 函数同名没关系 参数不同就可以
2014-10-27
展开全部
凭经验感觉你的提供的代码没问题,但是你可能在其它地方把point作为了模板形参或者系统内存在point的类型。建议你先把自己的point命名为point_tmp_2014_10_27 再编译试试看还报什么错误。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
distance函数重新命名 这个函数和std::distance()重名 把你的distance重新写个名字
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2014-10-26
展开全部
源码呢?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我发现using namespace std跟.h效果重复,把.h去掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询