rulururu

post Disable compiler warnings about unused variables

December 22nd, 2007

Filed under: C++ — Kai @ 2:55 pm

You might know warnings like this very well:

MyDialog.cpp: In member function ‘void MyDialog::Init()’:
MyDialog.cpp:79: warning: unused variable ‘btnClose’

It’s a simple and nice features compilers offer us but when projects are growing also the number of unused variables, the ones that are volitional unused, is growing. If you want to keep a clear head anyway what variables are unmeant unused you can use the following template:

template<typename T>
void ignore_unused(T const&) { }

Just put it into a file that is included at beginning. I usually have a glob.h which provides all defines and stuff like that to me.

Now you can determine yourself which variables shall not cause a warning:

ignore_unused(btnClose);

1 Comment »

  1. nice idea! thx

    Comment by Jeff — December 23, 2007 @ 1:45 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

ruldrurd
Powered by WordPress, Content and Design by Kai Bellmann
Entries (RSS) and Comments (RSS)