友元声明无效。。
<span style="background-color: rgb(255, 255, 255);">运行下列代码时,提示友元声明无效,请问是为什么。。?</span>file:///C:\Users\lenovo\Documents\Tencent Files\346411967\Image\C2C\6DS9EY3VARSVYAW@3
// Class.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Point
{
public:
Point(float x=0,float y=0);
void setPoint(float,float);
float getX(){return x;}
float getY(){return y;}
friend ostream & operater << (ostream &,const Point &);
protected:
float x,y;
};
Point::Point(float a, float b)
{
x=a;y=b;
}
void Point::setPoint(float a,float b)
{
x=a;y=b;
}
ostream &operater<<(ostream & output,Point &p)
{
output<<"["<<p.x<<","<<p.y<<"]";
return output;
}
int main()
{
Point p(4.3,5.2);
cout<<"x="<<p.getX()<<"y="<<p.getY()<<endl;
p.setPoint(5.6,7.6);
cout<<"p(new)"<<p<<endl;
return 0;
}
页:
[1]