I'm getting a strange warning

on cout test I'm getting a warning which says, the addres of test() will always evaluate as a true and it prints 1 forgetting the format of a complex...I know that it's return a true so the operator<< interpert that as a 1 and not as a complex...i think the problem comes from a default constructor...but I cant see the problem...here is my code

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
#include <stdio.h>
#include <iostream>

using namespace std;

class complex{
	public:
	int r ;
	int i ;
	
public:
	
	
	
	complex(int a = 0 ,int b = 0 ){
		r = a ? a:0;
		i = b ? b:0;
	};
	
	complex(const complex& temp){	//copy constructor
		r = temp.r;
		i = temp.i;
		
	}
	
	complex operator=(const complex& temp){		//copy assignament
		r = temp.r;
		i = temp.i;
		return *this;
	}
	
	complex(complex&& temp){			//move constructor
		r= temp.r;
		i = temp.i;
		
	}
	
	complex operator=(complex&& temp){		//move assignament
		r = temp.r;
		i = temp.i;
		return *this;
	}
	
};


ostream& operator<<(ostream& os,const complex& a){
	cout<<a.r<<" "<<a.i<< " "<<endl;
	return os;
}



int main(){
	
	complex test();
	complex test1(3,4);
	complex test5(45,6);
	cout<<test<<endl;
	cout<<test5<<endl;
	test5 = test1;
	return 0;

}


> complex test(); // 'test' is the name of a function

complex test ; // 'test' is the name of a default-initialised object

See: https://en.wikipedia.org/wiki/Most_vexing_parse
I dont understand i believe I have done that more times, and nothing happens...
1
2
3
4
5
6
7
int main(){
	
	//complex test(); // line 56
        complex test ;

	std::cout << test << '\n' ; 
}
I dont know but I think that I have always declared a n object without arguments like this
1
2
anyclass anyobjecte();
Topic archived. No new replies allowed.