2

In C++ I have a file A.cpp that has the following in it:

 namespace Foo {

     bool Bar() 
     { 
         return true; 
     }

 }

How would I declare this function in A.h? How do I handle the namespace?

2
  • Gee, I wonder what the answer is. :) Commented Jun 15, 2009 at 4:49
  • Yet another StackOverflow meme in the making? Commented Jun 15, 2009 at 4:51

4 Answers 4

7
namespace Foo {
  bool Bar();
}
Sign up to request clarification or add additional context in comments.

Comments

7
namespace Foo {
    bool Bar();
}

2 Comments

+1 for being character for character the same as John Dibling's answer with the same time stamp (rounded to the minute)
It's not actually. sharptooth spent 4 seconds on those two extra space characters and a newline. 45wpm... weak.
1
namespace Foo {
    bool Bar();
}

Comments

1
namespace Foo {
    bool Bar();
}

Or

/* don't look -- I must have been dreaming or mis-remembering -- the following does NOT work */
namespace Foo;
bool Foo::Bar();

3 Comments

You can use namespace Foo {} to wrap declarations and definitions in as many places as you want. It basically adds "Foo::" to the front of the name of everything inside the brackets. Things not inside a namespace that you name are in the default global namespace.
Nice second example. I'd never considered that approach.
Nice second example. Shame it doesn't compile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.