|
From: Robert Welz on 11 Jun 2008 08:10 Hello. I have to covert some code. Now the compiler moans about the template function but why? Template parameter struct caseless is correct, struct char_traits<caseless> looks good, but the empty template <> irritates me. I could not find any books on this. /Source/Grand Central Pro/GrandCentral/Develop/Mac/XRay Client 1.2.4 XCode/../../Common/HOSAL/Utils/Caseless.h:72: error: template-id 'assign<>' for 'void std::char_traits<std::caseless>::assign(std::caseless&, const std::caseless&)' does not match any template declaration /Source/Grand Central Pro/GrandCentral/Develop/Mac/XRay Client 1.2.4 XCode/../../Common/HOSAL/Utils/Caseless.h:72: error: invalid function declaration Is there someone who can guide me to the right direction? regards, Robert ---- // Case insensitive strings & chars #ifndef CASELESS_H #define CASELESS_H struct caseless { char c; caseless () : c(0) {} caseless (char ch) : c(ch) {} caseless (char* ch) : c(*ch) {} operator char() { return c; } operator const char() const { return c; } operator const char*() const { return (const char*)&c; } // operator int() // { return (int) c; } }; template <> struct char_traits<caseless> { typedef caseless char_type; typedef int int_type; typedef streamoff off_type; typedef streampos pos_type; typedef mbstate_t state_type; static void assign(char_type& c1, const char_type& c2); static bool eq(const char_type& c1, const char_type& c2); static bool lt(const char_type& c1, const char_type& c2); static int compare(const char_type* s1, const char_type* s2, size_t n); static size_t length(const char_type* s); static const char_type* find(const char_type* s, size_t n, const char_type& a); static char_type* move(char_type* s1, const char_type* s2, size_t n); static char_type* copy(char_type* s1, const char_type* s2, size_t n); static char_type* assign(char_type* s, size_t n, char_type a); static int_type not_eof(const int_type& c); static char_type to_char_type(const int_type& c); static int_type to_int_type(const char_type& c); static bool eq_int_type(const int_type& c1, const int_type& c2); static int_type eof(); }; template <> inline void char_traits<caseless>::assign(char_type& c1, const char_type& c2) { c1 = c2; } #endif // CASELESS_H
From: Bart van Ingen Schenau on 11 Jun 2008 14:30 Robert Welz wrote: > Hello. > I have to covert some code. > Now the compiler moans about the template function but why? Template > parameter struct caseless is correct, struct char_traits<caseless> > looks good, but the empty template <> irritates me. I could not find > any books on this. I found that you have to read the standard pretty carefully to pick it up, but the member-functions of an explicitly specialised template are just regular functions. Therefor, you should not use the 'template <>' prefix for their definition. Thus, the code should be: template <> struct char_traits<caseless> { static void assign(char_type& c1, const char_type& c2); // other members omitted for brevity. }; inline void char_traits<caseless>::assign(char_type& c1, const char_type& c2) { c1 = c2; } > > regards, > Robert > Bart v Ingen Schenau -- a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq c.l.c FAQ: http://c-faq.com/ c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
From: Robert Welz on 17 Jun 2008 08:55 Bart van Ingen Schenau <bart(a)ingen.ddns.info> wrote: .... Thanks for this clarification, regards, Robert
|
Pages: 1 Prev: most frequent value in a vector Next: question to (most frequent value in a vector)-answer |