Re: Explicitly specializing std::min() on VC++ 2005 Express Edition

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Matthias Hofmann wrote:
"Victor Bazarov" <v.Abazarov@xxxxxxxxxxxx> schrieb im Newsbeitrag
news:f1al1r$m1m$1@xxxxxxxxxxxxxxxxxx

Did you include the header where the 'std::min' template is actually
defined? Unless the compiler knows that 'std::min' is a template, it
cannot allow you to specialise it.

Yes, I did. Here's the complete code I am using:

#include <algorithm> // Defines std::min().
#include <cstring> // Defines std::strcmp().

namespace std
{
template <> inline const char*& min<>
( const char*& a, const char*& b )
{
return std::strcmp( a, b ) < 0 ? a : b;
}
}

int main()
{
return 0;
}

I also tried different signatures, like 'const char* min( const char*
a, const char* b )', but those gave me the same error code.

Add 'const' to the type of the object referred to by arguments:

template<> inline const char* const& min<>
( const char* const& a, const char* const& b) ...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


.



Relevant Pages

  • not being linked
    ... //util.h contains some usefull utility functions. ... template ... inline void printElements (const T& col, const char* pc="") ... Compiler: Default compiler ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Calling C functions from Forth
    ... I don't know yet whether pForth will be the final ... The C compiler I used was GCC. ... int strncmp (const char* str1, const char* str2, size_t num) ... stack, create the frame for C, and call the function. ...
    (comp.lang.forth)
  • Re: a few doubts!
    ... the warning messages are diagnostics. ... >> So what C compiler did you use that produced this incorrect messages? ... That causes string literals to be treated as "const char*" rather than ...
    (comp.lang.c)
  • Re: A doubly linked-list in C
    ... compiler gets there differently. ... you undefined behaviour. ... Use const char *p. ... that's the reason string literals aren't const. ...
    (comp.lang.c)
  • Re: String Comparision
    ... but got the following compiler error: ... -o c.exe c.c" (after unplugging my Microchip PICDEM 2 Plus ICD USB ... int comp(const restrict char *s, const char *t) { ...
    (comp.lang.c)