Skip to content

Instantly share code, notes, and snippets.

@Rcomian
Last active July 25, 2019 18:12
Show Gist options
  • Save Rcomian/15aa07df1478541f77d40bd09644d061 to your computer and use it in GitHub Desktop.
Save Rcomian/15aa07df1478541f77d40bd09644d061 to your computer and use it in GitHub Desktop.
C++ decentralised enum types
ENUM_CLASS::ENUM_CLASS() : id(nextid++) {}
int ENUM_CLASS::nextid = 0;
bool ENUM_CLASS::operator==(const ENUM_CLASS& other) const {
return id == other.id;
}
#pragma once
class ENUM_CLASS
{
public:
ENUM_CLASS();
bool operator==(const ENUM_CLASS& other) const;
protected:
const int id;
static int nextid;
};
#include "Usage.h"
int main() {
ENUM_CLASS a = MyObject::ENUM_VALUE_A;
if (a == MyObject::ENUM_VALUE_A) {
std::cout << "success" << std::emdl;
}
}
#include "EnumBase.hpp"
struct MyObject {
static ENUM_CLASS ENUM_VALUE_A;
static ENUM_CLASS ENUM_VALUE_B;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment