Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #15123

Re: Any way to defer template function overloading?

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c++
Subject Re: Any way to defer template function overloading?
Date 2012-04-02 11:02 +1200
Message-ID <9ts545FfaaU2@mid.individual.net> (permalink)
References <jl8d4h$hbf$1@speranza.aioe.org> <4f788f56$0$4347$7b1e8fa0@news.nbl.fi> <jlalgo$376$1@dont-email.me>

Show all headers | View raw


On 04/ 2/12 10:40 AM, Alf P. Steinbach wrote:
> On 01.04.2012 19:24, Juha Nieminen wrote:
>> Qi<no@no.no>   wrote:
>>> int main(int argc, char * argv[])
>>> {
>>>          (void)argc;
>>>          (void)argv;
>>
>>     This seemed like nonsensical code because it does nothing. Then I realized
>> that it's an ugly hack to silence the compiler warning about unused
>> variables. That's not how you do it.
>
> Right. I used to advocate a function template for that. But now I'd
> rather use a macro, e.g. like this:
>
>
> <code>
> #if !defined( CPP_DECLARE_UNUSED )
> #   define CPP_DECLARE_UNUSED( argName )    \
>           (void)(argName, void(), 0); struct argName; (void)0
> #endif
> // SO user sehe: "(void)0" for semicolon
> // SO user R. Martinho Fernandes, pointed out operator void() problem
> // SO user Johannes Schaub, solution to operator,() problem
> </code>
>
>
>>     The proper way of getting rid of the warnings is to not name the
>> parameters. If you still want to have their names visible, you can
>> simply comment them out:
>>
>>       int main(int /*argc, char** /*argv*/)
>
> But the names have documentary value, and those comments do not nest,
> e.g. for the purpose of commenting out code.

So include the names in the function declaration, but not in the definition.

-- 
Ian Collins

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Any way to defer template function overloading? Qi <no@no.no> - 2012-04-01 10:05 +0800
  Re: Any way to defer template function overloading? Ian Collins <ian-news@hotmail.com> - 2012-04-01 16:06 +1200
    Re: Any way to defer template function overloading? Qi <no@no.no> - 2012-04-01 13:53 +0800
  Re: Any way to defer template function overloading? Juha Nieminen <nospam@thanks.invalid> - 2012-04-01 17:24 +0000
    Re: Any way to defer template function overloading? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-04-02 00:40 +0200
      Re: Any way to defer template function overloading? Ian Collins <ian-news@hotmail.com> - 2012-04-02 11:02 +1200
      Re: Any way to defer template function overloading? Juha Nieminen <nospam@thanks.invalid> - 2012-04-02 05:29 +0000
    Re: Any way to defer template function overloading? Qi <no@no.com> - 2012-04-02 13:48 +0800
      Re: Any way to defer template function overloading? Ian Collins <ian-news@hotmail.com> - 2012-04-02 17:53 +1200
        Re: Any way to defer template function overloading? Qi <no@no.com> - 2012-04-02 13:57 +0800
          Re: Any way to defer template function overloading? Ian Collins <ian-news@hotmail.com> - 2012-04-02 18:12 +1200
            Re: Any way to defer template function overloading? Miles Bader <miles@gnu.org> - 2012-04-02 15:32 +0900
      Re: Any way to defer template function overloading? Miles Bader <miles@gnu.org> - 2012-04-02 14:58 +0900
      Re: Any way to defer template function overloading? Juha Nieminen <nospam@thanks.invalid> - 2012-04-02 10:11 +0000
        Re: Any way to defer template function overloading? Qi <no@no.com> - 2012-04-02 19:04 +0800
          Re: Any way to defer template function overloading? Qi <no@no.com> - 2012-04-02 19:17 +0800
  Re: Any way to defer template function overloading? jgk@panix.com (Joe keane) - 2012-04-02 14:41 +0000

csiph-web