0


What are the differences between wrapping related methods as static in an abstract non instantiating class versus using a namespace naming convention?

Class Wrapper

Utility.h

#pragma once

class Utility : final {
public:
    Utility() = delete;

    static functionDeclaration();
};

Utility.cpp

#include "Utility.h"

Utility::functionDefinition() {
}

Using Namespace

Utility.h

#pragma once

namespace util {
    functionDeclaration();
} // namespace util

Utility.cpp

#include "Utility.h"

// Namespace method 1:
using namespace util;

functionDefinition() {
}

// Namespace method 2:
util::functionDefinition() {
}

// Namespace method 3:
namespace util {
    functionDefinition() {
    }
} // namespace util

Are there any trade offs, advantages, disadvantages between the two? How does the compiler threat these differently?

Francis Cugler
  • 7,788
  • 2
  • 28
  • 59
  • Some of this discussion in this thread may help you: https://stackoverflow.com/questions/1434937/namespace-functions-versus-static-methods-on-a-class. This is not a 1:1 mapping with your problem, but a lot of the points raised shed light on your first question. – Daniel Mar 10 '18 at 23:12
  • @Daniel I will have to look at that. I searched on stack for similarly related questions and answers and couldn't seem to find anything relevant. – Francis Cugler Mar 10 '18 at 23:14
  • @Daniel Yes, that is exactly what I was looking for: thank you. It wasn't coming up in my searches. – Francis Cugler Mar 10 '18 at 23:25
  • You can vote to close this answer; Daniel had found what I couldn't find. – Francis Cugler Mar 10 '18 at 23:25

0 Answers0