Defined but not used? But I am using it!

Discussion in 'C++' started by Travis, Jun 27, 2007.

  1. Travis

    Travis Guest

    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!
     
    Travis, Jun 27, 2007
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Jun 28, 2007
    #2
    1. Advertising

  3. Travis

    Travis Guest

    On Jun 27, 5:35 pm, "Victor Bazarov" <> 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?
     
    Travis, Jun 28, 2007
    #3
  4. Travis

    Zeppe Guest

    Travis wrote:
    > On Jun 27, 5:35 pm, "Victor Bazarov" <> 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
     
    Zeppe, Jun 28, 2007
    #4
  5. Travis

    Jim Langston Guest

    "Travis" <> wrote in message
    news:...
    > On Jun 27, 5:35 pm, "Victor Bazarov" <> 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-lite/how-to-post.html#faq-5.8
     
    Jim Langston, Jun 28, 2007
    #5
  6. Travis

    Travis Guest

    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" <> 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
     
    Travis, Jun 28, 2007
    #6
  7. On Thu, 28 Jun 2007 07:01:41 +0000, Travis wrote:
    > On Jun 27, 5:35 pm, "Victor Bazarov" <> 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
     
    Markus Schoder, Jun 28, 2007
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kabeer
    Replies:
    6
    Views:
    3,229
    Thomas Matthews
    Aug 21, 2003
  2. William Payne

    Warning: Defined but not used

    William Payne, Feb 20, 2004, in forum: C++
    Replies:
    3
    Views:
    15,320
    William Payne
    Feb 20, 2004
  3. Eric Lilja
    Replies:
    3
    Views:
    1,079
    scott urban
    Jan 30, 2005
  4. Oodini
    Replies:
    1
    Views:
    1,779
    Keith Thompson
    Sep 27, 2005
  5. uche
    Replies:
    4
    Views:
    911
    Lionel B
    Feb 18, 2007
Loading...

Share This Page