8.30
今天写程序的时候产生了一个这样的错误
error:no type named iterator_category in struct
错误代码类似下面:
#include <iostream> #include <stdio.h> #include <math.h> using namespace std;
struct vertex { int x, y; }; double distance(const vertex& a, const vertex& b) { return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y)); } int main(int argc, char **argv) { vertex a, b; printf("%lf\n", vertex(a, b)); return 0; }
错误原因:函数命名存在问题。distance是STL中求迭代器距离的一个函数,这里冲突了。解决就是给distance换一个名字。