testBoolCastCompareDifferentType.cc
Go to the documentation of this file.
1 
8 #include <utl/SafeBoolCast.h>
9 
10 using namespace utl;
11 
12 
13 class C1 : public SafeBoolCast<C1> {
14 public:
15  bool BoolCast() const { return true; }
16 
17  int fI;
18 };
19 
20 
21 class C2 : public SafeBoolCast<C2> {
22 public:
23  bool BoolCast() const { return false; }
24 
25  double fD;
26 };
27 
28 
29 class Err1 {
30 public:
31  operator bool() const { return true; }
32 
33  int fI;
34 };
35 
36 
37 class Err2 {
38 public:
39  operator bool() const { return true; }
40 
41  int fI;
42 };
43 
44 
45 int
47 {
48  C1 o1;
49  C2 o2;
50 
51  Err1 oe1;
52  Err2 oe2;
53 
54  // this compiles
55  bool b = (oe1 == oe2);
56 
57  // this fails
58  const int bb = (o1 == o2);
59 
60  // to avoid additional warnings
61  b = bb;
62 
63  return 0;
64 }
bool BoolCast() const
bool BoolCast() const
int main(int argc, char *argv[])
Definition: DBSync.cc:58

, generated on Tue Sep 26 2023.