How do you create a static class?

If you’re looking for a way of applying the static keyword to a class, like you can in C# for example, then you won’t be able to without using Managed C++.

But the looks of your sample, you just need to create a public static method on your BitParser object. Like so:

BitParser.h

class BitParser
{
public:
  static bool getBitAt(int buffer, int bitIndex);

  // ...

  // Disallow creating an instance of this object
  // (Making all constructors private also works but is not ideal and does not
  // convey your intent as well)
  BitParser() = delete;
};

BitParser.cpp

bool BitParser::getBitAt(int buffer, int bitIndex)
{
  bool isBitSet = false;
  // .. determine if bit is set
  return isBitSet;
}

You can use this code to call the method in the same way as your example code.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)