菜鸟问题,求好心人解答。

m晴天vs小猪m 2012-03-16 10:58:09
#ifndef POINT_H
#define POINT_H

#include<iostream>
class Point{
public :
Point(int ,int );
Point(Point &);
~Point();
int get_x();
int get_y();
void put_x(int x);
void put_y(int y);
Point operator+(Point p);
Point operator*(int i);
Point operator>(Point p);
Point operator<(Point p);
int operator==(Point &p);
private :
int x;
int y;
friend istream& operator >> (istream & in , Point &p);
friend ostream& operator << (istream & out , Point &p);

}
#endif

类定义如上
使用vs2010进行编译
编译失败
log如下:


错误 1 error C2143: 语法错误 : 缺少“;”(在“&”的前面) x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
错误 2 error C2433: “istream”: 不允许在数据声明中使用“friend” x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
错误 3 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
错误 4 error C2061: 语法错误: 标识符“istream” x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
错误 5 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
错误 6 error C2805: 二进制“operator >>”的参数太少 x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
错误 7 error C2143: 语法错误 : 缺少“;”(在“&”的前面) x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
错误 8 error C2433: “ostream”: 不允许在数据声明中使用“friend” x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
错误 9 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
错误 10 error C2061: 语法错误: 标识符“istream” x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
错误 11 error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
错误 12 error C2805: 二进制“operator <<”的参数太少 x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
错误 13 error C1004: 发现意外的文件尾 x:\code\vs\data struct\类定义\类定义\类定义.cpp 27
14 IntelliSense: 未定义标识符 "istream" x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
15 IntelliSense: 未定义标识符 "istream" x:\code\vs\data struct\类定义\类定义\类定义.cpp 22
16 IntelliSense: 未定义标识符 "ostream" x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
17 IntelliSense: 未定义标识符 "istream" x:\code\vs\data struct\类定义\类定义\类定义.cpp 23
...全文
394 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
sghdls 2012-03-17
  • 打赏
  • 举报
回复

说错了, 这句没错, 是friend 晕了
sghdls 2012-03-17
  • 打赏
  • 举报
回复

friend istream& 中的 freind 写错了
sghdls 2012-03-17
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wzy26816812 的回复:]

加上后一样不成。。。。。
引用 5 楼 sghdls 的回复:
std:: 命名空间前面加了吗? std::istream
[/Quote]

把其它代码也贴上吧
zhxlianxin 2012-03-17
  • 打赏
  • 举报
回复
必须得加using namespace std;或者就明std::istream std::ostream
你试下,按照错误返回信息应该是这个错误,还有最后要再分号(这个我不知你是由于粘贴的原因还是。。。)
yhw8769607 2012-03-17
  • 打赏
  • 举报
回复
此头文件中的错误
friend istream& operator >> (istream & in , Point &p);
friend ostream& operator << (istream & out , Point &p);

1、参数怎么都是istream,下面的应该是ostream
2、开头需要声明using std::istream;using std::ostream
忘世麒麟 2012-03-17
  • 打赏
  • 举报
回复
错了,是不会再有错误!!!
同时记得把类声明放到.h文件中.
忘世麒麟 2012-03-17
  • 打赏
  • 举报
回复
类定义你应该放到头文件.h中不是.cpp文件中;
类声明后面少量";"
在开头添加上
using std::istream;
using std::ostream;
错误会少很多!
m晴天vs小猪m 2012-03-16
  • 打赏
  • 举报
回复
加上后一样不成。。。。。
[Quote=引用 5 楼 sghdls 的回复:]
std:: 命名空间前面加了吗? std::istream
[/Quote]
sghdls 2012-03-16
  • 打赏
  • 举报
回复

std:: 命名空间前面加了吗? std::istream
m晴天vs小猪m 2012-03-16
  • 打赏
  • 举报
回复
已经把中文文件名改掉了 还是不成。
[Quote=引用 3 楼 chiwa737 的回复:]
中文文件名啊
[/Quote]
chiwa737 2012-03-16
  • 打赏
  • 举报
回复
中文文件名啊
m晴天vs小猪m 2012-03-16
  • 打赏
  • 举报
回复
我使用的是vs2010 不是vc6

[Quote=引用 1 楼 czh3642210 的回复:]
你是用vc6编译的么
它对这个流类的友元支持不好,如果是的话,建议换个编译器
[/Quote]
面包大师 2012-03-16
  • 打赏
  • 举报
回复
你是用vc6编译的么
它对这个流类的友元支持不好,如果是的话,建议换个编译器

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧