不知道怎么解释friend和iostream.h之间的关系,谢谢指教!
#include<iostream>
using namespace std;
class vector{
double x,y;
public:
vector(double vx, double vy) {x=vx; y=vy;}
vector() {x=0; y=0;}
friend vector operator +(vector v1, vector v2); //加法(二元)运算符重载
void print( ){ cout<<x<<" "<<y<<"\n";}
};
vector operator + (vector v1, vector v2 )
{ vector v;
v.x=v1.x+v2.x;
v.y=v1.y+v2.y;
return v;
}
void main( )
{
vector v1(4.5,-7.8), v2(-1.5,1.2);
v1.print( );
v2.print( );
v1=v1+v2;
v1.print( );
}
但是有一个错误:
--------------------Configuration: exam - Win32 Debug--------------------
Compiling...
exam.cpp
G:\exam.cpp(9) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
Error executing cl.exe.
exam.obj - 1 error(s), 0 warning(s)
如果把
#include<iostream>
using namespace std;
改成
#include<iostream.h>
就没有问题。我不知道怎么解释friend和iostream.h之间的关系,谢谢指教!
问题点数:10、回复次数:3Top
1 楼bllue215(waveinfin)回复于 2004-12-02 13:17:23 得分 5
程序没有错误.
你却有一个思想错误:关键字跟标准库之间什么关系都没有
也不可能有!Top
2 楼zjraycj(无名)回复于 2004-12-02 14:24:19 得分 5
在VC中使用<iostream>时,友元重载+或-会出现错误,就是说VC对这个支持不好。不过改成<iostream.h>时则没有问题Top
3 楼yswang168()回复于 2004-12-02 22:52:44 得分 0
多谢两位大侠:
问题解决如下,将using namespace std; 改为 using std::cout; 即可。原因还不清楚。Top
相关问题
- .h
- 请解释:$this->h_acl->set_userdata($user);$this->m_TB_AGENT->change_gr_to_num),h_acl是个什么东西
- 请问那位大虾能解释一下.lib 和 .h 有什么不同?
- 谁跟我解释一下这些东西:ostream,fstream,iostream,ifstream 有什么区别与联系?
- mfc中有个 CSimpleList类在 AFXTLS_.h中 不知道有什么作用,看不懂 请高手解释
- MessageBox()属API函数,在MSDN中也有他的解释,可是我怎么知道他是哪个.h包涵的?MSDN中又没有说明,怎么办?
- 谁帮我解释解释?
- 谁给解释一下 CString的 operator + 函数为什么要定义成friend啊?
- iostream iterator
- <iostream.h> && <iostream>




