Skip to content

Instantly share code, notes, and snippets.

@metacollin
Last active Dec 5, 2018
Embed
What would you like to do?
#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