hello everyone, im a bit new to c++, im missing a concept of polymorphism. my problem is i cant figure out another way to override a method.
now this is just a very quick example that i wrote up but the thing is im not going to have much control of overriding it like that by saying
in the function thats going to be in a library that i will be importing into my main project, so the question i guess is, is their another way to override a method without going to the root of where it gets called? i have a feeling im missing something simple.
thank you for any help you give me
Code:
#include <iostream> class Base { public: Base(); ~Base(); public: virtual void OutPut() {std::cout << "Base" << std::endl;} }; class Derived : Base { public: Derived(); ~Derived(); public: virtual void OutPut() {std::cout << "Derived" << std::endl;} }; int main(){ Base* baseptr = new Derived; baseptr->OutPut(); }
Code:
Base* baseptr = new Derived;
thank you for any help you give me
Comment