Skip to content

Instantly share code, notes, and snippets.

@metacollin
Last active December 5, 2018 09:50
Show Gist options
  • Save metacollin/09b39068cf4b9bc1a60c82f8a24654a8 to your computer and use it in GitHub Desktop.
Save metacollin/09b39068cf4b9bc1a60c82f8a24654a8 to your computer and use it in GitHub Desktop.

Revisions

  1. metacollin revised this gist Dec 5, 2018. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions oop.cpp
    Original file line number Diff line number Diff line change
    @@ -61,13 +61,13 @@ int main()
    otherSub* test_class = new otherSub();
    myGeneric* generic_test = new mySub();

    // Output:
    getit(oSub); // myGeneric
    fuckit(oSub); // otherSub
    fuckit(teh_sub); // 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(&teh_sub); // mySub
    crushit(generic_test); // mySub

    return 0;
  2. metacollin created this gist Dec 5, 2018.
    74 changes: 74 additions & 0 deletions oop.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,74 @@
    #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;
    }