鱼C论坛

 找回密码
 立即注册
查看: 4310|回复: 1

友元声明无效。。

[复制链接]
发表于 2015-6-3 16:14:44 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. <span style="background-color: rgb(255, 255, 255);">运行下列代码时,提示友元声明无效,请问是为什么。。?</span>
复制代码

[img]file:///C:\Users\lenovo\Documents\Tencent Files\346411967\Image\C2C\6DS9EY3VARSVYAW@3[_0F_1.jpg[/img]

友元声明无效

友元声明无效
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2015-6-3 16:21:07 | 显示全部楼层
  1. // Class.cpp : 定义控制台应用程序的入口点。
  2. //

  3. #include "stdafx.h"
  4. #include <iostream>
  5. using namespace std;


  6. class Point
  7. {
  8. public:
  9.         Point(float x=0,float y=0);
  10.         void setPoint(float,float);
  11.         float getX(){return x;}
  12.         float getY(){return y;}
  13.         friend ostream & operater << (ostream &,const Point &);
  14. protected:
  15.         float x,y;
  16. };

  17. Point::Point(float a, float b)
  18. {
  19. x=a;y=b;
  20. }

  21. void Point::setPoint(float a,float b)
  22. {
  23. x=a;y=b;
  24. }

  25. ostream &operater<<(ostream & output,Point &p)
  26. {
  27.         output<<"["<<p.x<<","<<p.y<<"]";
  28.         return output;
  29. }


  30. int main()
  31. {
  32.         Point p(4.3,5.2);
  33.         cout<<"x="<<p.getX()<<"y="<<p.getY()<<endl;
  34.         p.setPoint(5.6,7.6);
  35.         cout<<"p(new)"<<p<<endl;
  36.         return 0;
  37. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-20 03:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表