class c_base_class {
protected:
. . .
public:
void run( ) {
std::cout << "Error: Run called from base class! \n";
};
};
class c_derived_class : public c_base_class {
protected:
. . .
public:
void run( ) {
std::cout << "Success: Run called from derived class \n";
};
class c_main {
protected:
std::vector<c_base_class*> listings;
public:
void push_base( c_base_class* base ) { listings.push_back( base ); };
void iterate ( ) {
for ( auto listing : listings) {
listing->run( );
};
};
void run( ) {
this->iterate( );
};
}; extern c_main* g_main;
. . .
void some_stuff::run( ) {
g_main->push_base( std::make_unique<c_derived_class>( . . . ).get( ) );
g_main->run( ); // Iterator calls base class 'run' function instead of derived classes 'run' function.
};
Excuse any mistakes/errors. This was purely pseudo I wrote on here, I believe it's pretty understandable what I'm trying to achieve.
If not here's a way of interpreting this, there are multiple derived classes so having a vector of just that one would be useless. I want to call run from the derived classes while just pushing back the base class into the vector as shown in the code but however the iterator just calls the base classes run function.