Öö Tiib wrote:
> On Sep 25, 3:08 pm, Rui Maciel <rui.mac...@gmail.com> wrote:
>> I have an abstract base class which defines an interface to a function
>> which takes 3 arguments. From that ABC I define a set of derived classes
>> which implements the base class' interface. The thing is, some derived
>> classes don't use some of the parameters, which causes the compiler to
>> throw warnings. As I'm not using those parameters intentionally, those
>> warnings tend to be a bit annoying.
>>
>> So, does anyone happen to know a good standard way to get the compiler to
>> stop warning about those specific instances where a parameter isn't used?
>
> One way is not to name the parameters, give only type:
>
> int foo( int )
> {
> return 0;
> }
>
> For me it is fine.
For me too.
> The downside that some claim it not documenting the
> intention well enough. They may use some macro or template that does
> not generate instructions:
>
> template<typename T>
> inline void UnusedParameter( T const& )
> {
> }
>
> #define UNUSED_PARAMETER(X) sizeof(X)
>
> int foo( int a, int b )
> {
> UNUSED_PARAMETER(a);
> UnusedParameter(b);
> return 0;
> }
>
> That perhaps documents everything well enough.
I think, this is worse. By giving names to the parameters, you actually make
it possible in the first place to use them. Those macros amount to nothing
more than comments and, given enough time, they _will_ turn false. The
compiler has no change anymore of catching things like:
int foo ( int a, int b )
{
UNUSED_PARAMETER(a);
return ( a*b );
}
Best
Kai-Uwe Bux
|