derived-class

Is there no way to upcast into an abstract class and not modify it each time a class is derived from it?

#include<iostream> using namespace std; class Abs { public: virtual void hi()=0; }; class B:public Abs { public: void hi() {cout<<"B Hi"<<endl;} void bye() {cout<<"B Bye"<<endl;} }; class C:public Abs { public: void hi() {cout<<"C Hi"<<endl;} void sayonara() {cout<<"C Sayo...

C++ fill array with objects derived from array type

In C++ I have an array of pointers to Player objects and want to fill it with Fickle objects where Fickle is a class that is derived from Player. This is because I want a general Player array that I can fill with different objects from different classes that all are derived from the Player class. How can I do this? I create an array o...

How to call child object's overloading function in polymorphism?

Consider the following simple polymorphism ... class Parent { public: someFunc() { /* implementation A */ }; }; class Child : public Parent { public: someFunc() { /* implementation B */ }; }; int main () { Parent* ptr; ptr = new Parent(); ptr->someFunc(); delete ptr; ptr = new Child(); ptr->someFunc()...

how to automate template typename specification with CLASSNAME<typename>(argument);

I'm creating a stat editor for some objects within a game world. Rather than have multiple edit menus for each object type, I just have one menu, and pass in a list/vector of stat-edit-objects which contain a pointer to the stat being edited, and the functions to do the work. struct StatEditObjPureBase { std::vector<std::string> rep...

cannot access protected variable in derived class c++

I have a Binary Search Tree as a derived class from a Binary Tree, right now I am trying to access the root for my recursive functions (which is in the base class). But for some reason I keep getting the error: binSTree.h:31: error: ‘root’ was not declared in this scope Here are my class declarations: base class: template <class T>...

Not calling base class constructor from derived class.

Say I have a base class: class baseClass { public: baseClass() { }; }; And a derived class: class derClass : public baseClass { public: derClass() { }; }; When I create an instance of derClass the constructor of baseClass is called. How can I prevent this? ...