嘿伙计们,我是 C++ 新手,每次我编译我的代码时,它总是说我在很多行上有一个 errorc2413,但我显然在那里有一个分号。每当我键入诸如 ex 之类的内容时,通常都会发生这种情况。复杂的。真实的。我想知道你能不能帮帮我?
using namespace std;
#include <iostream>
class Complex
{
private:
double real;
double imaginary;
public:
Complex()
{
real = 0.0;
imaginary = 0.0;
}
Complex(double r, double i)
{
real = r;
imaginary= i;
}
//Setters
void setReal(double r)
{
real = r;
}
void setImaginary(double i)
{
imaginary = i;
}
//Getters
double getReal()
{
return real;
}// end getReal
double getImaginary()
{
return imaginary;
}//end of getImaginary()
void output()
{
cout<< real <<" + i"<< imaginary;
}
Complex add(Complex a)
{
Complex result;
result.real= a.real + real;
result.imaginary = a.imaginary+imaginary;
return result;
}
Complex subtract(Complex a)
{
Complex result;
Complex.real = (real - a.real);
Complex.imaginary = (imaginary - a.imaginary);
return result;
}
Complex mul(Complex a)
{
Complex result;
Complex.real = (real*a.real)-(imaginary*a.imaginary);
Complex.imaginary = (real*a.imaginary)+(imaginary*a.real);
return result;
}
Complex div(Complex a)
{
Complex result;
result.real =
((real*a.real)+(imaginary*a.imaginary))/((a.real*a.real)+(a.imaginary+a.imaginary));
result.imaginary =
((imaginary*a.real)-(real*a.imaginary))/((a.real*a.real)+(a.imaginary+a.imaginary));
return result;
}
}//end complex class
1>----- 构建开始:项目:复数计算器,配置:调试 Win32 ------ 1> Calculator.cpp 1>c:\users\victor\documents\visual studio 2010\projects\complex数字计算器\复数计算器\calculator.cpp(3):错误 C2143:语法错误:缺少“;” 在“使用”之前 1>c:\users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(57):错误 C2143:语法错误:缺少“;” 前 '。' 1>c:\users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(57):错误C2143:语法错误:缺少';' 前 '。' 1>c:\users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(58):错误C2143:语法错误:缺少 ';' 前 '。' 1>c:\users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(58):错误C2143:语法错误:缺少';' 前 '。' 1>c:\users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(64):错误C2143:语法错误:缺少';' 前 '。' 1>c:\users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(64):错误C2143:语法错误:缺少';' 前 '。' 1>c:\users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(65): 错误 C2143: 语法错误: 缺少';' 前 '。' 1>c: \users\victor\documents\visual studio 2010\projects\复数计算器\复数计算器\complex.h(65):错误C2143:语法错误:缺少';' 前 '。' ========== 构建:0 成功,1 失败,0 最新,0 跳过 ==========