Thread: namespaces and static class members

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

    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, 11:43 AM
  2. Namespaces or package equivalent in C++
    By markcls in forum C++ Programming
    Replies: 10
    Last Post: 03-26-2007, 07:41 AM