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?

4
  • Some of this discussion in this thread may help you: stackoverflow.com/questions/1434937/…. This is not a 1:1 mapping with your problem, but a lot of the points raised shed light on your first question. Commented Mar 10, 2018 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. Commented Mar 10, 2018 at 23:14
  • @Daniel Yes, that is exactly what I was looking for: thank you. It wasn't coming up in my searches. Commented Mar 10, 2018 at 23:25
  • You can vote to close this answer; Daniel had found what I couldn't find. Commented Mar 10, 2018 at 23:25

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.