Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Defined but not used? But I am using it!

Reply
Thread Tools

Defined but not used? But I am using it!

 
 
Travis
Guest
Posts: n/a
 
      06-27-2007
I can't figure this out. So in a templated class of mine I have the
following.

namespace menutree
{
static bool debug = false;
}


And in various parts of the code I have statements like.

if (menutree::debug) { std::cout << "here" << std::endl;

Everything compiles but I get the warning

"warning: `bool menutree::debug' defined but not used"

Can someone shed some light on this?

Thanks!

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-28-2007
Travis wrote:
> I can't figure this out. So in a templated class of mine I have the
> following.
>
> namespace menutree
> {
> static bool debug = false;
> }


You have a namespace _in_ "a templated class"? How so?

> And in various parts of the code I have statements like.
>
> if (menutree::debug) { std::cout << "here" << std::endl;
>
> Everything compiles but I get the warning
>
> "warning: `bool menutree::debug' defined but not used"
>
> Can someone shed some light on this?


I think this is covered by the FAQ 5.8.

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


 
Reply With Quote
 
 
 
 
Travis
Guest
Posts: n/a
 
      06-28-2007
On Jun 27, 5:35 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
> Travis wrote:
> > I can't figure this out. So in a templated class of mine I have the
> > following.

>
> > namespace menutree
> > {
> > static bool debug = false;
> > }

>
> You have a namespace _in_ "a templated class"? How so?
>
> > And in various parts of the code I have statements like.

>
> > if (menutree::debug) { std::cout << "here" << std::endl;

>
> > Everything compiles but I get the warning

>
> > "warning: `bool menutree::debug' defined but not used"

>
> > Can someone shed some light on this?

>
> I think this is covered by the FAQ 5.8.
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask


Sorry not IN the template, in the template .h file but outside the
template's definition.

FAQ 5.8?

 
Reply With Quote
 
Zeppe
Guest
Posts: n/a
 
      06-28-2007
Travis wrote:
> On Jun 27, 5:35 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
>> Travis wrote:
>>> I can't figure this out. So in a templated class of mine I have the
>>> following.
>>> namespace menutree
>>> {
>>> static bool debug = false;
>>> }

>> You have a namespace _in_ "a templated class"? How so?
>>
>>> And in various parts of the code I have statements like.
>>> if (menutree::debug) { std::cout << "here" << std::endl;
>>> Everything compiles but I get the warning
>>> "warning: `bool menutree::debug' defined but not used"
>>> Can someone shed some light on this?

>> I think this is covered by the FAQ 5.8.
>>
>> V
>> --
>> Please remove capital 'A's when replying by e-mail
>> I do not respond to top-posted replies, please don't ask

>
> Sorry not IN the template, in the template .h file but outside the
> template's definition.
>
> FAQ 5.8?
>


aka "too little code to help". Perhaps you use the variable in a
template that is never instantiated?

Regards,

Zeppe
 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      06-28-2007
"Travis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> On Jun 27, 5:35 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
>> Travis wrote:
>> > I can't figure this out. So in a templated class of mine I have the
>> > following.

>>
>> > namespace menutree
>> > {
>> > static bool debug = false;
>> > }

>>
>> You have a namespace _in_ "a templated class"? How so?
>>
>> > And in various parts of the code I have statements like.

>>
>> > if (menutree::debug) { std::cout << "here" << std::endl;

>>
>> > Everything compiles but I get the warning

>>
>> > "warning: `bool menutree::debug' defined but not used"

>>
>> > Can someone shed some light on this?

>>
>> I think this is covered by the FAQ 5.8.
>>
>> V
>> --
>> Please remove capital 'A's when replying by e-mail
>> I do not respond to top-posted replies, please don't ask

>
> Sorry not IN the template, in the template .h file but outside the
> template's definition.
>
> FAQ 5.8?


http://www.parashift.com/c++-faq-lit...t.html#faq-5.8


 
Reply With Quote
 
Travis
Guest
Posts: n/a
 
      06-28-2007
On Jun 28, 1:01 am, Zeppe
<zep_p@.remove.all.this.long.comment.yahoo.it> wrote:
> Traviswrote:
> > On Jun 27, 5:35 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
> >>Traviswrote:
> >>> I can't figure this out. So in a templated class of mine I have the
> >>> following.
> >>> namespace menutree
> >>> {
> >>> static bool debug = false;
> >>> }
> >> You have a namespace _in_ "a templated class"? How so?

>
> >>> And in various parts of the code I have statements like.
> >>> if (menutree::debug) { std::cout << "here" << std::endl;
> >>> Everything compiles but I get the warning
> >>> "warning: `bool menutree::debug' defined but not used"
> >>> Can someone shed some light on this?
> >> I think this is covered by the FAQ 5.8.

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

>
> > Sorry not IN the template, in the template .h file but outside the
> > template's definition.

>
> > FAQ 5.8?

>
> aka "too little code to help". Perhaps you use the variable in a
> template that is never instantiated?
>
> Regards,
>
> Zeppe


Oh I am sorry. I apologize. I'm a little knew to the groups and
posting code, etc.

This should be it: http://cpp.sourceforge.net/?show=37775

 
Reply With Quote
 
Markus Schoder
Guest
Posts: n/a
 
      06-28-2007
On Thu, 28 Jun 2007 07:01:41 +0000, Travis wrote:
> On Jun 27, 5:35 pm, "Victor Bazarov" <(E-Mail Removed)> wrote:
>> Travis wrote:
>> > I can't figure this out. So in a templated class of mine I have the
>> > following.

>>
>> > namespace menutree
>> > {
>> > static bool debug = false;
>> > }

>>
>> You have a namespace _in_ "a templated class"? How so?
>>
>> > And in various parts of the code I have statements like.

>>
>> > if (menutree::debug) { std::cout << "here" << std::endl;

>>
>> > Everything compiles but I get the warning

>>
>> > "warning: `bool menutree::debug' defined but not used"

>>
>> > Can someone shed some light on this?

>>
>> I think this is covered by the FAQ 5.8.

>
> Sorry not IN the template, in the template .h file but outside the
> template's definition.


Since "debug" is static you get a new instance for each translation unit
this header file is included in (directly or indirectly). Now there
probably is a translation unit where you do not use "debug" and that is
where the compiler complains since you have a static variable that is not
used in a given translation unit and since it cannot be used in a
different translation unit that does not seem to make sense.

Assuming you do not want to change the value of "debug" at run-time try
to declare it as

namespace menutree
{
const bool debug = false;
}

This allows for better optimization and hopefully silences the compiler
as well.

--
Markus Schoder
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: __STDC_IEC_559__ (defined or !defined ?) Keith Thompson C Programming 0 08-17-2010 04:36 PM
User-defined exception: "global name 'TestRunError' is not defined" jmike@alum.mit.edu Python 1 07-10-2008 12:37 PM
defined? for recursive function call v/s defined? for function call stack Alok Ruby 3 04-13-2006 11:53 AM
Using parenthesis with defined (#if defined(...)) Angel Tsankov C++ 1 04-05-2006 10:00 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM



Advertisments