namespaces and static class members

This is a discussion on namespaces and static class members within the C++ Programming forums, part of the General Programming Boards category; Say I had Code: using namespace algo { int func() { return 5; } }; and Code: class algo { ...

  1. #1
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493

    namespaces and static class members

    Say I had
    Code:
    using namespace algo {
      int func() { return 5; }
    };
    and
    Code:
    class algo {
    public:
      static int func() { return 5; }
    };
    Is there any difference? The only one I can find is that you can declare all the members of a class friends where you can't with namespaces.

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    If the only purpose for your class is going to be to contain these static functions, then I see reason to prefer one over the over (aside from preference, that is). The one downfall classes have (if they are being used as namespaces like this), is that you have to declare away the constructors to prevent one from ever being created.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Declaring instances of different implementations
    By dwks in forum C++ Programming
    Replies: 8
    Last Post: 07-16-2008, 12:43 PM
  2. Namespaces or package equivalent in C++
    By markcls in forum C++ Programming
    Replies: 10
    Last Post: 03-26-2007, 08:41 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21