2
votes
1answer
152 views

How do multiple levels of inheritance affect virtual function call overhead in C++?

I am considering using a class hierarchy with more than a single level of inheritance, where virtual member functions form a "chain", for example: struct Base { virtual void foo(); }; struct D1 : ...
1
vote
2answers
150 views

Is it an anti-pattern to use void* and enums to enable type-checking?

Say in a game engine, you have Objects that composited of different components. One of these is a RenderComponent which can be either a Mesh, a Sprite or a Light. Now, all these are vastly different ...
1
vote
4answers
262 views

Combinatorial explosion of interfaces: How many is too many?

I'm a relative newcomer to OOP, and I'm having a bit of trouble creating good designs when it comes to interfaces. Consider a class A with N public methods. There are a number of other classes, B, C, ...
0
votes
1answer
193 views

Does C++ support subtyping?

I know it might be a silly question to ask, but I didn't quite get an a absolute clear answer on this matter, so I thought I'd put it here. Does c++ support the subtyping in the sense that it ...
1
vote
3answers
385 views

Is it bad practice to check object types with an identifying member variable?

Preamble: I am making a simple board game in C++, in which AI characters move around squares on the board. There are different types of squares, each inherited from an abstract class, each with ...
2
votes
2answers
1k views

Interview question “What is virtual function”

It was funny for me, and I'm interesting the reaction for this question of the community. It was interview for C++/Qt developer, and question was asked "What is virtual function". Not something like ...
7
votes
4answers
579 views

Design pattern for polymorphic behaviour while allowing library separation

Let's say I have a hierarchy of Item classes: Rectangle, Circle, Triangle. I want to be able to draw them, so my first possibility is add a virtual Draw() method to each: class Item { public: ...
12
votes
6answers
510 views

OO Design, how to model Tonal Harmony?

I have started to write a program in C++ 11 that would analyse chords, scales, and harmony. The biggest problem I am having in my design phase, is that the note 'C' is a note, a type of chord (Cmaj, ...
3
votes
3answers
2k views

How to setup the c++ rule of three in a virtual base class

I am trying to create a pure virtual base class (or simulated pure virtual) my goal: User can't create instances of BaseClass. Derived classes have to implement default constructor, copy ...
5
votes
13answers
892 views

Limitations of Polymorphism in statically typed languages

I program mostly in statically typed languages, like C++ and Java. A common strategy employed in languages like these to handle dealing with collections of objects which are related, but which need ...
0
votes
4answers
556 views

Objective-C message passing related queries

I am learning objective-C after having good knowledge of C/C++. I have 2 questions: Are Obj-C message passing and C++ vtable, two different ways of implementing polymorphism or Are they two very ...