operator () overloaded

I have my class complex with most of the facilities needeed to do operations...

I have created a Add class with the goal of overload operator () (just to learn)...what I'm trying to do is call that operator with a Add obj and with and complex argument...but in the call the compiler is giving me an error...I don't know why I can not call and I can't imagine the way to do it...does anyone know how to?,thanks...

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <cstdio>
#include <iostream>


using namespace std;  	


class complex {
		double re,im;
	public:
			//constructor
		complex(double a = 0,double b = 0):re{a},im{b}{};
		
		//copy operations.
		
		complex(const complex& obj){		//copy constructor
			re = obj.re;
			im = obj.im;
			
		}
		
		complex operator=( complex& obj){	//copy assignament
				re = obj.re;
				im = obj.im;
				return *this;
		}
		
		//operators
		complex operator+(complex a){	//complex plus complex
			re += a.re;
			im += a.im;
			return *this;
		}
		complex operator+(double a){	//complex plus double
			complex temp;
			temp.re = a + this->re;
			temp.im = a + this->im;
			return  temp;
		}
		
		complex operator+(int a){		//complex plus int
			complex temp;
			temp.re = a + this->re;
			temp.im = a + this->im;
			return  temp;
		
		}
		
		complex operator*(complex& a){		//complex times complex
			re = re * a.re;
			im = im * a.im;
			return *this;
		}
		
		
		
		double get_re () const{
			return re;
		}
		
		double get_im () const {
			return im;
		}
		
		void set_re(double num){
			this->re = num;
			
		}
		
		void set_im(double num){
			this->im = num;
			
		}
		
		complex operator+=(const complex& obj){
				
			re = re + obj.re;
			im =im + obj.im;
			return *this;
		}

};

class Add{
	public:
	complex val;
public: 
	Add(complex c):val{c}{}
	Add(double re,double im){
		val.set_re(re);
		val.set_im(im);
	}
	
	void operator()(complex& c)const { c += val;}
};

ostream& operator<<(ostream& os,const Add& obj){
	cout<<obj.val.get_re()<<" "<<obj.val.get_im()<<endl;
	return os;
}




int main(){
	Add test(1,1);
	complex test2(2,2);
	test.(test2);
	cout<<test2<<endl;
	
well, I have just found out that without putting the dot operator(line 108) it works...but I dont know how....that is way is how to call a function and test is an object of Add....does anyone have an explanation?thanks
Topic archived. No new replies allowed.