Skip to content

Instantly share code, notes, and snippets.

@sherief
Created July 22, 2014 18:41
Show Gist options
  • Save sherief/c2b0a46b775ec688f5b9 to your computer and use it in GitHub Desktop.
Save sherief/c2b0a46b775ec688f5b9 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cassert>
using namespace std;
typedef unsigned long long uint64;
template<uint64 high, uint64 low>
class cookie
{
public:
cookie()
{
High = high;
Low = low;
}
void check()
{
cookie Cookie;
assert(*this == Cookie);
}
private:
bool operator==(const cookie& RHS)
{
return (High == RHS.High) && (Low == RHS.Low);
}
uint64 High, Low;
};
typedef cookie<0xAABBCCDDAABBCCDD, 0x1122334455667788> foo_cookie;
class foo
{
public:
void do_stuff()
{
Cookie.check();
cout << "Foo doing stuff!\n";
}
private:
foo_cookie Cookie;
};
int main(int argc, char *argv[])
{
foo Foo;
char stuff[128];
foo* F1 = &Foo; //Pointer to an actual foo object
foo* F2 = (foo*)stuff; //Pointer to what's definitely not an actual foo object
F1->do_stuff();
F2->do_stuff();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment