Last active
December 5, 2018 09:50
-
-
Save metacollin/09b39068cf4b9bc1a60c82f8a24654a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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