编译问题,大家帮帮忙。
编译出现了3个错误,都是fatal error C1001: INTERNAL COMPILER ERROR,且都指向three_d.h 的
friend three_d operator+(const three_d &obj_1, const three_d &obj_2);
该如何解决,赐教!
下面是我的代码,分为3个.cpp和2个.h文件:
//main.cpp
#include <iostream>
using namespace std;
#include "test.h"
#include "three_d.h"
void main(void)
{
test menu;
}
//three_d.h
#ifndef THREE_D_H
#define THREE_D_H
class three_d
{
private:
int x, y, z;
void init();
public:
three_d();
three_d(int a,int b,int c);
~three_d();
friend three_d operator+(const three_d &obj_1, const three_d &obj_2);
friend three_d operator--(three_d &obj, int);
friend ostream &operator<<(ostream &out, const three_d &obj);
friend istream &operator>>(istream &in, three_d &obj);.
three_d operator++();
three_d operator-=(const three_d &obj);
};
#endif
//three_d.cpp
#include <iostream>
using namespace std;
#include "three_d.h"
void three_d::init()
{
cout << "Input the three_d : ";
cin >> x >> y >> z;
}
three_d::three_d()
{
init();
}
three_d::three_d(int a,int b,int c) : x(a), y(b), z(c)
{}
three_d::~three_d(){}
three_d three_d::operator ++()
{
++x;
++y;
++z;
return *this;
}
three_d three_d::operator -=(const three_d &obj)
{
x -= obj.x;
y -= obj.y;
z -= obj.z;
return *this;
}
three_d operator+(const three_d &obj_1, const three_d &obj_2)
{
return three_d(obj_1.x + obj_2.x, obj_1.y + obj_2.y, obj_1.z + obj_2.z);
}
three_d operator--(three_d &obj, int)
{
x--;
y--;
z--;
return *this;
}
ostream &operator<<(ostream &out, const three_d &obj)
{
out << "The three_d is : ";
out << odj.x;
out << ", ";
out << obj.y;
out << ", ";
out << obj.z;
out << endl;
return out;
}
istream &operator>>(istream &in, three_d &obj)
{
in >> obj.x;
in >> obj.y;
in >> obj.z;
return in;
}
//test.h
#ifndef TEST_H
#define TEST_H
class test
{
public:
test();
~test();
void menu();
};
#endif
//test.cpp
#include <iostream>
using namespace std;
#include "test.h"
#include "three_d.h"
test::test(){}
test::~test(){}
void test::menu()
{
char ch;
cout << "选项\n";
cout << "================================================\n";
cout << "1、两对象求和 2、对象对自身求差\n";
cout << "3、前自增 4、后自减\n";
cout << "5、退出\n";
cout << "================================================\n\n";
do
{
cout << "选择 : ";
cin >> ch;
switch(ch)
{
case '1' : three_d obj_1, obj_2;
cout << obj_1 + obj_2 << endl;
break;
case '2' : three_d obj_1, obj_2;
cout << obj_1 -= obj_2 << endl;
break;
case '3' : three_d obj;
cout << ++obj << endl;
break;
case '4' : three_d obj;
cout << obj-- << endl;
break;
case '5' : return;
default : cout << "错误的选择!\n";
}
cout << "继续操作?[是(Y or y) / 不(any other key)]";
}while ( (cin.get() == 'Y') || (cin.get() == 'y') );
}