Topic: utility templates and conversions


Author: dent@highway1.com.au (Andy Dent)
Date: 1997/09/28
Raw View
As I read DWP (downloaded from http://www.setech.com/x3.html) section
13.3.3 a user-defined conversion is more desirable than a template
specialization. If I'm right, does the following conform to that situation?

/* program to test behaviour of ANSI libraries
  which appear to be instantiating a template operator <=
  from utility.h without specification of a template!

if uncomment the #include <utility> get the following error:

Error   : cannot convert
'bool' to
'const queryClause'
testOverload.cpp line 25   searchTest(b1 <= b2);


*/

#include <utility>

class queryClause {
public:
   queryClause();
};

class theBase {
public:
   queryClause operator<=(int) const;
   operator int() const;
};

// prototype for typical search function
void searchTest(const queryClause&);

int
main() {
   theBase b1, b2;
   searchTest(b1 <= int(b2)); // OK
   searchTest(b1 <= b2);   // triggers compiler error if include <utility>
   return 0;
}

--
Andy Dent, Software Designer, A.D. Software, Western Australia
OOFILE - "the cross-platform OODBMS that speaks c++"
ftp://ftp.highway1.com.au/pub/adsoftware/
http://www.highway1.com.au/adsoftware/
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]