impl override property

an anonymous user · May 04, 2021 · C++
#include <iostream>
#include <vector>

class BaseClass
{
    public:
        BaseClass()
        {
            std::cout << "ctor base" << "\n";
            test = 5;
        }
        int test = 0;
        
        int getTest()
        {
            return test;
        }
        
};

class ImplementingClass : public BaseClass
{
    public:
        ImplementingClass()
        {
            std::cout << "ctor impl" << "\n";
            test = 12;
        }
        // int test = 12;
};

int main() {
    std::vector<BaseClass> collection;
    ImplementingClass t;
    collection.emplace_back(t);
    
    for (auto a : collection)
    {
        std::cout << a.getTest();
    }
    
    return 0;
}

Comments

Please sign up or log in to contribute to the discussion.