Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我的C++;在更复杂的cin和cout中调用iostream重载时失败? 在C++类中有过载的IoFoad遇到麻烦,下面的代码是我的头文件,所以没有主()。重载的iostream似乎可以处理简单的cin和cout调用,但当放入更复杂的_C++_Iostream - Fatal编程技术网

为什么我的C++;在更复杂的cin和cout中调用iostream重载时失败? 在C++类中有过载的IoFoad遇到麻烦,下面的代码是我的头文件,所以没有主()。重载的iostream似乎可以处理简单的cin和cout调用,但当放入更复杂的

为什么我的C++;在更复杂的cin和cout中调用iostream重载时失败? 在C++类中有过载的IoFoad遇到麻烦,下面的代码是我的头文件,所以没有主()。重载的iostream似乎可以处理简单的cin和cout调用,但当放入更复杂的,c++,iostream,C++,Iostream,为什么我的C++;在更复杂的cin和cout中调用iostream重载时失败? 在C++类中有过载的IoFoad遇到麻烦,下面的代码是我的头文件,所以没有主()。重载的iostream似乎可以处理简单的cin和cout调用,但当放入更复杂的调用时,它不会抛出与operato>匹配的调用 /* 提供三个构造函数Complex(a、b)、Complex(a)和Complex()。复合物() 为数字0创建一个复杂对象,复杂(a)为b创建一个0的复杂对象。 还提供用于返回的getReal

为什么我的C++;在更复杂的cin和cout中调用iostream重载时失败?

在C++类中有过载的IoFoad遇到麻烦,下面的代码是我的头文件,所以没有主()。重载的iostream似乎可以处理简单的cin和cout调用,但当放入更复杂的调用时,它不会抛出与operato>匹配的调用

/*
提供三个构造函数Complex(a、b)、Complex(a)和Complex()。复合物()
为数字0创建一个复杂对象,复杂(a)为b创建一个0的复杂对象。
还提供用于返回的getRealPart()和getImaginaryPart()函数
复数的实部和虚部。
*/
/*
重载运算符+、-、*、/、+=、-=、*=、/=、[]、一元+和-、前缀++和--,
后缀++和--、。重载运算符+、-、*、/作为非成员函数。
*/
#包括
#包括
#包括
#包括
使用名称空间std;
阶级情结{
公众:
复合物();
复合物(双a);
复合物(双a,双b);
无效集_I(双输入);
无效集(双输入);
双get\u I\u comp()const;//I访问器
double get\u R\u comp()const;//双访问器
双getRealPart();
双getImaginaryPart();
复数运算符+(复数其他);
复合运算符+(双其他);
复数运算符-(复数其他);
复算子-(双重其他);
复数运算符*(复数其他);
复数运算符*(双其他);
复算子/(复其它);
复算子/(双其它);
void运算符++();
复数&运算符++(int-dummy);
void运算符+=(复杂其他);
无效运算符+=(双倍其他);
void运算符-=(复杂其他);
无效运算符-=(双倍其他);
无效运算符*=(双其他);
void运算符*=(const Complex和其他);
无效运算符/=(双倍其他);
void操作符/=(const Complex和其他);
void算子-();
void运算符+();
双精度&运算符[](整数索引);
复数和运算符(常量字符串和输出);
friend ostream&operator(恒流与输入、复杂与目标);
std::string toString()//当前的临时解决方案
{
如果(此->c_I!=0){
字符串ret=std::to_字符串(c_R);
ret=ret+“+”;
ret=ret+std::to_字符串(c_I);
ret=ret+“i\n”;
返回ret;
}
否则{
字符串ret=std::to_字符串(c_R);
返回ret;
}
}
复合和添加(双数);
复杂和添加(复杂其他);
复数&减法(双数);
复数&减法(复数其他);
复数和乘法(双数);
复数&乘法(复数其他);
复数与除法(双数);
复合与分割(复合其他);
复杂&abs();
私人:
双c_I;
双c_R;
};
Complex::Complex():c_I(0),c_R(0){//works
}
复数:复数(双a):c_I(0),c_R(a){//works
}
Complex::Complex(double a,double b){//works//首先我将I作为a,r作为b,所以这就是翻转的原因
这->c_I=b;
这->c_R=a;
}
双复数::get_I_comp()常量{
返回c_I;
}
双复数::get_R_comp()常量{
返回c_R;
}
双复数::getImaginaryPart(){
返回c_I;
}
双复数::getRealPart(){
返回c_R;
}
void Complex::set_I(双输入){
c_I=输入;
}
void Complex::set_R(双输入){
c_R=输入;
}
复数::运算符+(复数其他){
复杂ret((this->c_R+other.get_R_comp()),(this->c_I+other.get_I_comp());
返回(ret);
}
复数::运算符+(其他双精度){
复杂ret(this->c_R+other,this->c_I);
返回ret;
}
复杂操作符-(复杂其他){
复杂ret(this->c_R-other.get_R_comp(),this->c_I-other.get_I_comp());
返回ret;
}
Complex::运算符-(双重其他){
复杂ret(this->c_R-其他,this->c_I);
返回ret;
}
复数::运算符*(双其他){
复杂ret(此->c_R*其他,此->c_I*其他);
返回ret;
}
复数::运算符*(复数其他){
if((other.get\u comp()!=0)和&(other.get\u comp()!=0)){
复杂ret=其他*(此->c\U R);
复杂neu(-(other.get\u-comp()*this->c\u-I),other.get\u-comp()*this->c\u-I);
返回(ret+neu);
}
if((其他.get_I_comp()=0)和&(其他.get_R_comp()!=0)){
复杂ret(this->c\u R,this->c\u I);
ret=ret*other.get_R_comp();
返回ret;
}
否则{
复杂ret((((this->c_I)*other.get_I_comp()),(this->c_R)*other.get_comp());
返回ret;
}
}
复数复数::运算符/(双倍其他){
如果(其他==0){//0除法错误处理程序
抛出运行时_错误(“数学错误:不能按零除法\n”);
返回1;
}
如果(其他!=0){
复杂ret(this->c\u R/other,this->c\u I/other);
返回ret;
}
}
//要将a+bi除以c+id,我们将执行操作(ac+bd)/(c^2+d^2)+(bc ad)/(c^2+d^2)i。
复数复数::运算符/(复数其他){
if((other.get\u comp()!=0)和&(other.get\u comp()!=0)){
双优先=((this->c_R)*other.get_R_comp()+(this->c_I)*other.get_R_comp())/(other.get_R_comp()*other.get_R_comp()+other.get_R_comp()*other.get_R_comp());
双秒=(此->c_I*其他.get_R_comp()+c_R*其他.get_I_comp())/(其他.get_R_comp()*其他.get_R_comp()+其他.get_I_comp()*其他.get_I_comp());
复合ret(第一、第二);
返回ret;
}
if((其他.get_I_comp()=0)和&(其他.get_R_comp()!=0)){
复杂ret(this->c\u R,this->c\u I);
ret=ret*(1/other.get_R_comp());
返回ret;
}
否则{
复杂ret(this->c\u R,this->c\u I);
复杂neu(1/other.get_I_comp());
ret=ret*neu;
返回ret;
}
}
void Complex::运算符++(){
c_R++;
}
复数和复数::运算符++(int-dummy){
复杂温度=*此温度;
++温度;
c_R++;
返回温度;
}
void Complex::运算符+=(其他双精度){
c_R+=其他;
}
void Complex::operator+=(Complex-other){
c_R+=other.get_R_comp();
c_I+=其他。获取_I_comp();
}
void Complex::运算符-=(其他双精度){
c_R+=(-1*其他);
}
虚空复合体::
main.cpp:19:69: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream’ and ‘Complex’)
  cout << "(" << number1 << ")" << " + " << "(" << number2 << ") = " << (number1 + number2) << endl;
In file included from main.cpp:1:0:
Complex.h:276:10: note: candidate: std::ostream& operator<<(std::ostream&, Complex&) 
 ostream& operator<<(ostream& out, Complex& target){
ostream& operator<<(ostream& out, Complex&& target){
  out << "Real : ";
  out << " " << target.getRealPart();
  out << " imaginary :";
  out <<target.getImaginaryPart();
  return out;
}
    ostream& operator<<(ostream& out, Complex const& target)
    ostream& operator<<(ostream& out, Complex target)