Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created July 13, 2015 12:50
Show Gist options
  • Save krysseltillada/78ff6cbe7a1da1b90f66 to your computer and use it in GitHub Desktop.
Save krysseltillada/78ff6cbe7a1da1b90f66 to your computer and use it in GitHub Desktop.
constexpr constructors
#include <iostream>
class Debug {
public:
constexpr Debug (bool a, bool b, bool c):
hw (a), io (b), other (c) { }
constexpr Debug() : Debug(false, false, false) { }
constexpr Debug (bool aa) : Debug (false , false ,false) { }
constexpr Debug (bool aaa, bool bb) : Debug (false, false, false) { }
void set_io (bool);
bool set_any ();
void set_other (bool);
void set_hw (bool);
private:
bool hw, io, other;
};
void Debug::set_hw (bool bbbb) {
this->hw = bbbb;
}
void Debug::set_io (bool b) {
this->io = b;
}
bool Debug::set_any () {
return hw || io || other;
}
void Debug::set_other (bool bbb) {
this->other = bbb;
}
int main ()
{
Debug test (true, true, true);
if (test.set_any())
std::cerr << "prints error (need debugging)" << std::endl;
else
std::cerr << "doesnt need debug" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment