主题:运算符重载调试问题!
调试不能通过,错误在哪里?帮忙看下,我新手 ^.^
//成员函数运算符重载,友元函数运算符重载;
#include "iostream"
using namespace std;
class complex //复数类;
{
public:
complex(int m, int n)
{
a = m;
b = n;
}
inline void printf() const
{
cout<<"("<<a<<", "<<b<<")"<<endl;
}
complex operator+(const complex &c);//成员函数运算符重载
//友元函数运算符重载
friend complex operator-(const complex &x1, const complex &x2);
//protected:
private:
int a;
int b;
};
complex complex::operator+(const complex&x)
{
complex t;
t.a = a + x.a;
t.b = b + x.b;
return t;
}
complex operator-(const complex &x1, const complex &x2)
{
complex t;
t.a = x1.a - x2.a;
t.b = x1.b - x2.b;
return t;
}
void main()
{
complex a(2, 5), b(3, 8);
(a+b).printf();
(a-b).printf();
}
调试错误:
--------------------Configuration: 0108-7 - Win32 Debug--------------------
Compiling...
0108-7.cpp
D:\c程序\std1218\0108-7.cpp(22) : 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.
0108-7.exe - 1 error(s), 0 warning(s)
//成员函数运算符重载,友元函数运算符重载;
#include "iostream"
using namespace std;
class complex //复数类;
{
public:
complex(int m, int n)
{
a = m;
b = n;
}
inline void printf() const
{
cout<<"("<<a<<", "<<b<<")"<<endl;
}
complex operator+(const complex &c);//成员函数运算符重载
//友元函数运算符重载
friend complex operator-(const complex &x1, const complex &x2);
//protected:
private:
int a;
int b;
};
complex complex::operator+(const complex&x)
{
complex t;
t.a = a + x.a;
t.b = b + x.b;
return t;
}
complex operator-(const complex &x1, const complex &x2)
{
complex t;
t.a = x1.a - x2.a;
t.b = x1.b - x2.b;
return t;
}
void main()
{
complex a(2, 5), b(3, 8);
(a+b).printf();
(a-b).printf();
}
调试错误:
--------------------Configuration: 0108-7 - Win32 Debug--------------------
Compiling...
0108-7.cpp
D:\c程序\std1218\0108-7.cpp(22) : 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.
0108-7.exe - 1 error(s), 0 warning(s)