I am learning to design classes and I have found a source file of the book "C ++ for C programmers" in which an elementary implementation is made for complex numbers (I already know that the type exists complex in the STL , but what interests me is learning to design elementary classes); the fact is that the linker gives me the error LNK1561 , as if I had forgotten the function main
...
// An elementary implementation of type complex
#include <iostream> //IO library
#include <string> //string type
using namespace std;
class complex {
public: //universal access to interface
void re_assign(double r) { real = r; }
void im_assign(double im) { imaginary = im; }
void print() const
{
cout << "(" << real << ","
<< imaginary << "i)" << endl;
}
friend complex operator+(complex, complex);
private: //restricted access to implementation
double real, imaginary;
};
//overload +
complex operator+(complex x, complex y)
{
complex t;
t.real = x.real + y.real;
t.imaginary = x.imaginary + y.imaginary;
return t;
}
int main()
{
complex x, y, z;
x.re_assign(9.5);
x.im_assign(-4.5);
y.re_assign(4.2);
y.im_assign(6.0);
z = x + y;
x.print();
y.print();
z.print();
int look; cin >> look;
}