Re: About template!

From: Crosbie Fitch (crosbie_at_cyberspaceengineers.org)
Date: 02/24/04


Date: Tue, 24 Feb 2004 11:01:52 +0000 (UTC)


"Simon Trew" <ten.egnaro@werts> wrote in message
news:OuKGTAi%23DHA.1804@TK2MSFTNGP12.phx.gbl...
> Hmm, Kim says extern, you say static. Either way , I can't get it to work.

Well, static storage, global linkage, named.

So you can't use a string literal, or a const string (cos it'll be given
internal linkage) - oops.

So your string has to be defined as:

char MyString[]="An external linkage string";

Then your template can be:

template <char* p>
class Fub....

or

template <const char* p>

And you can then go

Fub<MyString> AFub;

>
> I agree with you that you have to wonder why you'd want this on a char*.
> But a more general pointer argument might occasionally be useful to supply
> something along the lines of a "traits class" if, for some reason, the
> usually way of doing a traits class was not possible.

Sure.



Relevant Pages

  • injection_projection code
    ... because of hex encoding. ... a row in the template. ... Sanitize string to protect against email header injection. ... void injection_protection(char *s) ...
    (freebsd-isp)
  • Re: Cheap (simple, efficient) solution for literal strings in templates?
    ... >> I couldn't make that work with the strings as template arguments. ... best of all I'd like the ability to just write a string directly ... if the context requires 'char', then it's 'char', and ditto for 'wchar_t'. ... template< typename Char> ...
    (comp.lang.cpp)
  • Re: Strings in C
    ... defined as part of the language definition? ... Its storage depends on where it is defined. ... difference to the storage of the string. ... String literals always have static storage, and last until the end of the program. ...
    (comp.lang.c)
  • Re: String questions
    ... For example I could have a string: ... The caller could provide the buffer and let the ... The called function could allocate the storage ... static storage outlasts the execution of any single ...
    (comp.lang.c)