-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0.c
29 lines (28 loc) · 865 Bytes
/
0.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class ComplexNumber {
private:
int re, im;
public:
constexpr ComplexNumber(const int a, const int b) : re(a), im(b) {}
constexpr ComplexNumber() : re(0), im(0) {}
constexpr int GetRe() const { return re; }
constexpr int GetIm() const { return im; }
constexpr int SetRe(int arg) { return re = arg; }
constexpr int SetIm(int arg) { return im = arg; }
constexpr bool operator==(const ComplexNumber& x) const {
return (re == x.re) && (im == x.im);
}
constexpr ComplexNumber Conjugate(const ComplexNumber&);
~ComplexNumber() = default;
};
constexpr ComplexNumber Conjugate(const ComplexNumber& x) {
ComplexNumber res;
res.SetRe(x.GetRe());
res.SetIm(-x.GetIm());
return res;
}
int main() {
constexpr ComplexNumber a(1, 2);
constexpr ComplexNumber b(1, -2);
constexpr auto c = Conjugate(a);
static_assert(b == c, "failed");
}