Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Placing them in a <code>namespace</code> is an option. I don't see the need for a class. An instance of a class is mean to represent a state, but you're describing a bunch of free functions, so a stateless system.</p> <p>"It is not worth of wraping every function into single class." - this is not a valid argument for making the decision not to write a class. A class can have a single member and a single method, but if there is logic behind it, you should write it.</p> <p>If your functions and your logic mandates the use of a class, where your functions have the same logic but operate differently depending on the object, by all means, write a class. If your sole purpose is to group the functions together, when their logic doesn't really rely on the same instance of a class, group them in a namespace. </p> <p>An example based on your question:</p> <pre><code>namespace NetworkHelpers { //free function, use a namespace bool pingServer(std::string hostname); } //alternative, where the object has a state: class ServerConnection { std::string _hostname; public: NetworkHelpersClass(std::string hostname) { _hostname = hostname; } bool pingServer() { return NetworkHelpersNamespace::pingServer(_hostname); } }; </code></pre> <p>As you can see, inside the namespace, the function doesn't depend on anything other than the parameter.</p> <p>Inside the class, since it has a state and you create an object for each server (so similar behavior, yet different depending on the object), you call the function with no parameters as the object has a state.</p> <p>I hope this makes it clear.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload