Linked Questions
196 questions linked to/from What is an example of the Liskov Substitution Principle?
0 votes
2 answers
75 views
Pointer to a Superclass object may serve as pointers to subclass objects. But can't call memeber functions of the subclass. why?
I am enrolled in a C++ course, where i have the following code snippet: class Pet { protected: string name; public: Pet(string n) { name = n; } void run() { ...
0 votes
1 answer
147 views
Call a derived class function not in base class without dynamic casting to maximize performance
I am implementing an AVLTree in C++ as an exercise as preparation for future projects. An AVLTree is basically a BSTTree but with the extra detail that the tree is balanced, i.e., for a node x with ...
1 vote
2 answers
114 views
Can an Air Conditioner remote be considered polymorphic (in context of OOP)?
I know its a weird question but I was asked this in an interview by the CEO of a software house, First, he asked if a remote could be considered an Object, If yes then explain why? If it is an object ...
0 votes
1 answer
224 views
Accessing child class variables through parent class
I am making a simple 2D physics engine for circles and squares. I have a body class that I want to be given a unique_ptr instance of a shape when created. The shape can either be a circle or a box. ...
-1 votes
1 answer
110 views
OOP for global system/task monitoring class
I'm trying to create a performance monitor of sorts to run on a Particle board (STM32 based). I'm used to programming in c so the OOP approach is a bit new but I think it would fit well here. For the ...
3 votes
1 answer
128 views
If static methods cannot be overriden, why must they satisfy the exception throws contract of the static method in the parent? [duplicate]
Since static functions belong to a class, they are inherited but not overridden, merely hidden. From the code below, it seems that the woof method in B can only have a "throws IOException" declaration ...
1 vote
1 answer
94 views
Where to place objects in an generic abstract class concept?
Note: See the update below, as I altered the original concept, based on the first answer+comment I'm sorry if this is a trivial question or if it solely depends on the programmers preference. As I am ...
0 votes
1 answer
102 views
dynamic cast with inheritance hierarchies
so I have this code: Base* objbase = new Derived(); //perform a downcast at runtime with dynamic_cast Derived* objDer = dynamic_cast<Derived*>(objBase); if(objDer)//check for success of the ...
2 votes
2 answers
72 views
Why my code does two instances instead of one?
Why my code does two instances, one for the parent class and one for the child class. I figure the code in the main() ask for only one. I try to unsterstand why that's happen, but no idea coming to my ...
0 votes
1 answer
115 views
Parent Class having an Array of Child Class
With c++, I am trying to create a class called "family". Family is parent class of child class "man," and I'm trying to create an array of "man" in family class, but in order to do that, I need to ...
-1 votes
1 answer
142 views
Return pointer to derived class from base class
I would like to now if the following is possible. I have a templated class called A which inherits from a class called Base. In Base I set a write() function to be rewritten for every derived class. I ...
0 votes
0 answers
142 views
C++ how to utilize public int from subclass in a different subclass
I'm practicing a prototype program for a text-based game with complex character features. I have simplified much of what I already wrote, but I'm new to programming and have run into a problem. I ...
0 votes
3 answers
109 views
How the inheritance of Java should be? [closed]
Currently I have admin class, user class and lecturer class. Then I want user and lecturer inherit from user. But the problem is my user class constructor is about the username, password, but the ...
-5 votes
1 answer
68 views
How to implement virtual inteface C++
Say I have an interface defined as: class MyInterface : public virtual ObjectInterface { public: virtual bool MyFunc() = 0; }; Then I have a class which adopts this interface, in the header file:...
1 vote
2 answers
70 views
How extract a child class and all its child class from a list?
and sorry for the weird title. There is my class hierarchy : TimedObject SpeedModifer ImediateSpeedModifier LinearSeedModifier .. More classes .. .. More classes .. In the files, all TimedObject's ...