写了一个关于类的代码,环境是VS2017,出现错误:
错误 LNK2019 无法解析的外部符号 _main,该符号在函数 "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 中被引用
代码如下:
(complex.h)
#pragma once
#include<string>
using namespace std;
class Complex {
public:
Complex(double r = 0, double i = 0);//构造函数
Complex add(Complex &r);//复数加
Complex sub(Complex &r);
Complex mul(Complex &r);
Complex div(Complex &r);
string str();//转换成字符串
private:
double real, img;//定义实部和虚部
};
(complex.cpp)
#include"Complex.h"
Complex::Complex(double r, double i) {
real = r;
img = i;
}
Complex Complex::add(Complex &r) {
return Complex(this->real + r.real, this->img + r.img);
}
Complex Complex::sub(Complex &r) {
return Complex(real - r.real, img - r.img);
}
Complex Complex::mul(Complex &r) {
double r1 = real * r.real - img * r.img;
double i1 = real * r.img + img * r.real;
return Complex(r1, i1);
}
Complex Complex::div(Complex &r) {
double k = r.real*r.real + r.img*r.img;
double r1 = (real*r.real + img * r.img) / k;
double i1 = (img*r.real - real * r.img) / k;
return Complex(r1, i1);
}
string Complex::str() {
char s[100];
sprintf(s, "(%g,%g)", real, img);
return string(s);
}
(m1.cpp)
#include<iostream>
using namespace std;
#include"Complex.h"
int main()
{
Complex a(1, 2), b(3, 4);
cout << "a+b=" << a.add(b).str() << endl;
cout << "a-b=" << a.sub(b).str() << endl;
cout << "a*b=" << a.mul(b).str() << endl;
cout << "a*b/b=" << a.mul(b).div(b).str() << endl;
return 0;
}
求大神帮帮我这个蒟蒻吧