我正在尝试重载输出和输入流操作符,但在编译时会出现此错误
错误1错误LNK2019:未解析的外部符号“类 std :: basic_istream> &安培; __cdecl 运算符>>(类std :: basic_istream
&,class complex const&)“(?? 5 @ YAAAV?$ basic_istream @ DU?$ char_traits @ D @ std @@@ std @@ AAV01 @ ABVComplex @@@ Z) 在函数中引用 _main C:\ Users \ owner \ Documents \ Personal \ practice \ main.obj practice
基本上我试图读取用户输入并将其解析为实数和虚数
Complex.h
#pragma once
#include <iostream>
using namespace std;
class Complex
{
public:
Complex(void);
~Complex(void);
friend ostream& operator<<(ostream&, const Complex &C);
friend istream& operator>>(istream&, const Complex &C);
int real;
int imaginary;
};
Complex.cpp
#include "Complex.h"
using namespace std;
Complex::Complex()
{
real = 0;
imaginary = 0;
}
Complex::~Complex(void)
{
}
ostream &operator<<(ostream &output, const Complex &C)
{
char symbol = '+';
if (C.imaginary < 0)
symbol = '-';
output << C.real << ' ' << symbol << ' ' << abs(C.imaginary) << 'i';
return output;
}
istream &operator>>(istream &input, Complex &C)
{
int tempReal;
char symbol;
char tempImaginaryFull[2];
int tempImaginary;
input >> tempReal >> symbol >> tempImaginaryFull;
C.real = tempReal;
tempImaginary = tempImaginaryFull[0];
C.imaginary = tempImaginary;
if( symbol == '-')
C.imaginary *= -1;
return input;
}
我真的不知道那个错误意味着什么,即使我已经尝试过寻找它。