Thread: using s specific namespace in all class members, using directive in class header

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    40

    using s specific namespace in all class members, using directive in class header

    Hi everyone, I have some memory that it was possible to write something like this:
    Code:
    class MySpecialClass
    {
    public:
        using namespace boost;
    };
    And then was boost namespace visible in all member functions of that class, but of course have I forget exactly how to write it. What is the right syntax to accomplish this? I have been started to get tired of written using directive in every member function

    Thanks in advance.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Perhaps you are thinking of using that using directive at global scope, after all the includes, in the source file containing the definitions of the various member functions of MySpecialClass.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    40
    Yes, that will work, but it feels wrong and with that memory in my head is it very annoying. I haven't sleep this night either so it can be it too, but if you don't know so are it probably impossible.

    Thanks anyway.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Unfortunately it seems to me that you can't use using declarations at class scope.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by anon
    Unfortunately it seems to me that you can't use using declarations at class scope.
    You can, and that would be appropriate to bring in names from a base class that would be hidden otherwise.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Perhaps I meant using directives then - can't remember which is which. It seems to me that you can't put "using namespace boost;" where the OP wants to put it.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    It is not possible to use "using namespace" directives in a class definition.

    However, there are other forms of "using" directives that are used (no pun intended) within classes.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 08-04-2009, 11:40 AM
  2. Problem with friend class declaration in a namespace
    By Angus in forum C++ Programming
    Replies: 2
    Last Post: 12-09-2008, 01:29 PM
  3. Using Vector for Members of a Class
    By bengreenwood in forum C++ Programming
    Replies: 11
    Last Post: 12-04-2007, 03:31 PM
  4. Class methods in header or source file?
    By TriKri in forum C++ Programming
    Replies: 13
    Last Post: 09-17-2007, 05:23 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM