class operations test

in the above code it prints 12 from a.displaya();
and then it doesnt print c.displaya()

is there an explanation about that??
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
class A{
	int a;
public:
	A(int i) {a=i;}
	
	

	void operator()(const A & a )
	{
		this->a+=a.a+4;
		
	}

	const A operator+(const A& a)
	{
		return A(this->a +a.a);
	}

	const A& operator=(const A& a)
	{
		this->a =a.a;
		return *this;
	}
	
	int diplaya(void){return a;};
};
void main( void )
{

A a(4);
A b(5);
A c(4);

a(a);
cout<<a.diplaya();
c=a+b;
c.diplaya();
int k;
cin>>k;
}
I'm absolutely positively sure that you can find this error yourself. Come on!!! :-)
maybe because i need this??because of the return A(this->a +a.a);
(inside the const A operator+(const A& a){return A(this->a +a.a);})

1
2
3
4
A(const A& a)
	{
		this->a =a.a;
	}


but if i put his in the class it doesnt go in there
No no, you just forgot a 'cout<<' in front of 'c.diplaya();'
no my mistake i didnt write it here

it doesnt write something even if the cout exists..
Well, let's see the version of the program that you have troubles with. If I add 'cout<<' in front of 'c.diplaya();' in your program, it works exactly as I would expect it to. It writes '12' followed by '17'.
Last edited on
sory you are correct
i am a little confused from too much studying i have to do a break..

thank you!!
Topic archived. No new replies allowed.