Skip to content

Instantly share code, notes, and snippets.

@metacollin
Last active December 5, 2018 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metacollin/09b39068cf4b9bc1a60c82f8a24654a8 to your computer and use it in GitHub Desktop.
Save metacollin/09b39068cf4b9bc1a60c82f8a24654a8 to your computer and use it in GitHub Desktop.
#include <iostream>
class myGeneric
{
public:
myGeneric()
{
};
virtual void id()
{
std::cout << "myGeneric" << std::endl;
};
};
class mySub : public myGeneric
{
public:
void id() override
{
std::cout << "mySub" << std::endl;
};
};
class otherSub : public myGeneric
{
public:
void id() override
{
std::cout << "otherSub" << std::endl;
};
};
void getit(myGeneric generic)
{
generic.id();
}
void fuckit(myGeneric &generic)
{
generic.id();
}
void crushit(myGeneric* generic)
{
generic->id();
}
int main()
{
mySub teh_sub;
otherSub oSub;
otherSub* test_class = new otherSub();
myGeneric* generic_test = new mySub();
// Output:
getit(oSub); // myGeneric
fuckit(oSub); // otherSub
fuckit(teh_sub); // mySub
fuckit(*generic_test); // mySub
crushit(test_class); // otherSub
crushit(&teh_sub); // mySub
crushit(generic_test); // mySub
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment