friend ostream &operator << (ostream &output, point<Type> &p);哪里错了

来源:百度知道 编辑:UC知道 时间:2024/07/07 20:32:41
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

#ifndef POINT_H
#define POINT_H

template < class Type>
class point
{
public:
//point() {}
point(Type a, Type b) : x(a), y(b) {};
point(point &a)
{
x = a.x;
y = a.y;
}
~point() {};
Type getx() { return x; }
Type gety() { return y; }
point<Type> operator + (point<Type> &a);
point<Type> operator - (point<Type> &a);
Type operator * (point<Type> &a);
Type cross(point<Type> &a);
int operator == (point<Type> &a);
friend ostream &operator << (ostream &output, point<Type> &p);
private:
Type x, y;
};

#endif

template <class Type> int point<Type>::operator == (point<Type> &a)
{
return (x =

你的友元<<实则是个名字空间域函数而不是类域函数,不会因为你写了friend,它就是类的成员。这样,它本身不会自动变成模板函数,那参数表中的Type,从何且来呢?
你本意只是这个函数能接受这个模板类,是不是这个函数也应该是模板函数呢,接受这个模板类的参数呢?
函数前加上一行:
template <class Type>

函数的参数错了,你好好想